Hidden costs and legalities

What happens if my renovation uncovers old code violations?