Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return *all* custom mapping errors, not just the first one #2743

Merged
merged 1 commit into from
Dec 13, 2024

Conversation

iwahbe
Copy link
Member

@iwahbe iwahbe commented Dec 13, 2024

The only semantic change in this PR is here:

@@ -1408,20 +1409,20 @@ func (g *Generator) gatherResource(rawname string,
 	}

 	// Ensure there weren't any custom fields that were unrecognized.
+	var errs []error
 	for key := range info.Fields {
 		if _, has := schema.Schema().GetOk(key); !has {
 			msg := fmt.Sprintf("there is a custom mapping on resource '%s' for field '%s', but the field was not "+
 				"found in the Terraform metadata and will be ignored. To fix, remove the mapping.", rawname, key)
-
 			if cmdutil.IsTruthy(os.Getenv("PULUMI_EXTRA_MAPPING_ERROR")) {
-				return nil, errors.New(msg)
+				errs = append(errs, errors.New(msg))
+			} else {
+				g.warn(msg)
 			}
-
-			g.warn(msg)
 		}
 	}

-	return res, nil
+	return res, errors.Join(errs...)
 }

 func (g *Generator) gatherDataSources() (moduleMap, error) {

The rest is just renaming "github.com/pkg/errors" from errors to pkgerrors so we can add an un-aliased "errors".

The only semantic change in this PR is here:

```patch
@@ -1408,20 +1409,20 @@ func (g *Generator) gatherResource(rawname string,
 	}

 	// Ensure there weren't any custom fields that were unrecognized.
+	var errs []error
 	for key := range info.Fields {
 		if _, has := schema.Schema().GetOk(key); !has {
 			msg := fmt.Sprintf("there is a custom mapping on resource '%s' for field '%s', but the field was not "+
 				"found in the Terraform metadata and will be ignored. To fix, remove the mapping.", rawname, key)
-
 			if cmdutil.IsTruthy(os.Getenv("PULUMI_EXTRA_MAPPING_ERROR")) {
-				return nil, errors.New(msg)
+				errs = append(errs, errors.New(msg))
+			} else {
+				g.warn(msg)
 			}
-
-			g.warn(msg)
 		}
 	}

-	return res, nil
+	return res, errors.Join(errs...)
 }

 func (g *Generator) gatherDataSources() (moduleMap, error) {
```

The rest is just renaming "github.com/pkg/errors" from `errors` to `pkgerrors` so we can
add an un-aliased `"errors"`.
@iwahbe iwahbe requested a review from a team December 13, 2024 12:17
@iwahbe iwahbe self-assigned this Dec 13, 2024
Copy link

codecov bot commented Dec 13, 2024

Codecov Report

Attention: Patch coverage is 13.63636% with 19 lines in your changes missing coverage. Please review.

Project coverage is 69.64%. Comparing base (3a5eb93) to head (6b5edbb).
Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
pkg/tfgen/generate.go 13.63% 18 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2743   +/-   ##
=======================================
  Coverage   69.63%   69.64%           
=======================================
  Files         301      301           
  Lines       38725    38726    +1     
=======================================
+ Hits        26968    26969    +1     
+ Misses      10241    10240    -1     
- Partials     1516     1517    +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@iwahbe iwahbe merged commit 5b45441 into master Dec 13, 2024
17 checks passed
@iwahbe iwahbe deleted the iwahbe/return-all-provider-mapping-errors branch December 13, 2024 14:10
@pulumi-bot
Copy link
Contributor

This PR has been shipped in release v3.98.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants