One can always sue a contractor for breach of contract if the contractor’s work is below the standard of others in the industry. For instance we sued a contractor who failed to put proper floor joists in the second floor addition. The Contractor was obligated to pay for the costs to fix this problem.
If these defects are not readily apparent, then there is an implied warranty of habitability that the residential building be habitable and constructed properly. Sometimes the building is failing and you do not find this out until many years later. Courts have allowed homeowners to sue the contractor to fix the problem.