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

Add a Warnings() method to tfdiags.Diagnostics #36387

Closed
SarahFrench opened this issue Jan 22, 2025 · 3 comments · Fixed by #36392
Closed

Add a Warnings() method to tfdiags.Diagnostics #36387

SarahFrench opened this issue Jan 22, 2025 · 3 comments · Fixed by #36392
Labels
enhancement good first issue new new issue not yet triaged

Comments

@SarahFrench
Copy link
Member

Terraform Version

N/A

Use Cases

Diagnostics type variables are collections of diagnostics returned from code. They can include a mixture of Error or Warning diagnostics. Calling code can receive a diagnostics list and use HasErrors or HasWarnings to check if the diagnostics includes at least one diagnostic with that severity level.

It'd be useful to add a Warnings() method to Diagnostics that returns all the contained warning diagnostics within a new Diagnostics collection.

Attempted Solutions

N/A

Proposal

I imagine the method would look very similar to:

func getWarnings(diags tfdiags.Diagnostics) tfdiags.Diagnostics {
// Collect warnings
warnDiags := tfdiags.Diagnostics{}
if diags.HasWarnings() {
for _, d := range diags {
if d.Severity() == tfdiags.Warning {
warnDiags = warnDiags.Append(d)
}
}
}
return warnDiags
}

References

@SarahFrench
Copy link
Member Author

This task came up during a PR I was working on, and I figured it'd be a useful good first issue for anyone wanting an easy start to begin contributing.

@momowind-su
Copy link

I would like to work on this issue

@crw
Copy link
Contributor

crw commented Jan 22, 2025

Hi @momowind-su, if you’re interested in contributing to Terraform, please begin by reviewing the contributing guide and following the process outlined there. Thanks for your interest!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement good first issue new new issue not yet triaged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants