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

WIP: Fix error handling #2972

Closed
wants to merge 2 commits into from
Closed

WIP: Fix error handling #2972

wants to merge 2 commits into from

Conversation

mkcp
Copy link
Contributor

@mkcp mkcp commented Sep 6, 2024

Description

Currently this WIP PR adds some error handling within utils/yaml.go. The intent is to address one or part of the concerns in #2950 & #2951, after understanding the scope of the changes more. I just wanted to address some low hanging fruit that I found in the meantime.

Related Issue

Relates to #2953

Checklist before merging

@mkcp mkcp requested review from a team as code owners September 6, 2024 01:15
@mkcp mkcp marked this pull request as draft September 6, 2024 01:16
Copy link

netlify bot commented Sep 6, 2024

Deploy Preview for zarf-docs canceled.

Name Link
🔨 Latest commit dc9a5d6
🔍 Latest deploy log https://app.netlify.com/sites/zarf-docs/deploys/66da58e31b08ab00082a6e28

Copy link

codecov bot commented Sep 6, 2024

@@ -36,8 +36,11 @@ func yamlFormat(attr color.Attribute) string {
}

// ColorPrintYAML pretty prints a yaml file to the console.
func ColorPrintYAML(data any, hints map[string]string, spaceRootLists bool) {
text, _ := goyaml.Marshal(data)
func ColorPrintYAML(data any, hints map[string]string, spaceRootLists bool) error {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add error handling around input

@@ -18,10 +18,13 @@ import (
"github.com/zarf-dev/zarf/src/pkg/utils"
)

func (p *Packager) confirmAction(stage string, warnings []string, sbomViewFiles []string) bool {
func (p *Packager) confirmAction(stage string, warnings []string, sbomViewFiles []string) (bool, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed to be updated to handle errors from ColorPrintYAML. Alternatively we might be able to just quietly error or debug log these if Packager has access to a logger and they're low impact. Very open to feedback here!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great question! This is low impact, but we're trying to get rid of all the quiet debugs, unless there is a good reason for it. This is a benign example, but there were plenty of places in the code where we continued because it might not cause a problem and that made implementations confusing and harder to read. If goyaml.Marshall errors there probably is something pretty bad going on, though 99.999% of the time it will be fine unless there's an actual issue in our code.

@mkcp
Copy link
Contributor Author

mkcp commented Sep 10, 2024

Closing this one out to avoid changes to packager for now.

@mkcp mkcp closed this Sep 10, 2024
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.

2 participants