-
Notifications
You must be signed in to change notification settings - Fork 582
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
fix: ensure nested legacycli invocations forward errors #5709
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -457,14 +457,16 @@ func displayError(err error, userInterface ui.UserInterface, config configuratio | |
if err != nil { | ||
_, isExitError := err.(*exec.ExitError) | ||
_, isErrorWithCode := err.(*cli_errors.ErrorWithExitCode) | ||
if isExitError || isErrorWithCode { | ||
if isExitError || isErrorWithCode || errorHasBeenShown(err) { | ||
return | ||
} | ||
|
||
if config.GetBool(output_workflow.OUTPUT_CONFIG_KEY_JSON) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be the only remaining changes to main. |
||
message := getErrorMessage(err) | ||
|
||
jsonError := JsonErrorStruct{ | ||
Ok: false, | ||
ErrorMsg: err.Error(), | ||
ErrorMsg: message, | ||
Path: globalConfiguration.GetString(configuration.INPUT_DIRECTORY), | ||
} | ||
|
||
|
@@ -543,6 +545,9 @@ func MainWithErrorCode() (int, []error) { | |
outputWorkflow, _ := globalEngine.GetWorkflow(localworkflows.WORKFLOWID_OUTPUT_WORKFLOW) | ||
outputFlags := workflow.FlagsetFromConfigurationOptions(outputWorkflow.GetConfigurationOptions()) | ||
rootCommand.PersistentFlags().AddFlagSet(outputFlags) | ||
// add output flags as persistent flags | ||
_ = rootCommand.ParseFlags(os.Args) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question: What is the incorrect behaviour you were seeing which required this change? I am not sure I understand how it is related to the change you are looking to make here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The configuration values were not being populated properly (eg: even if the --json flag was in the args, the configuration flag for the JSON output would have the default value of false). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can probably be removed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: this is still needed to properly populate the configuration, since we need it for the cliv2/internal/cliv2/cliv2.go: useSTDIO := c.globalConfig.GetBool(configuration.WORKFLOW_USE_STDIO)
jsonEnabled := c.globalConfig.GetBool(output_workflow.OUTPUT_CONFIG_KEY_JSON)
hasBeenDisplayed := false
if useSTDIO && jsonEnabled {
hasBeenDisplayed = true
} If you remove it and test against There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I removed these changes locally @CatalinSnyk, but have not yet been able recreate the behaviour you described.
Output
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you sure you had the newest changes pulled? With that exact lines removed, I just clean built it locally and i get the following:
|
||
globalConfiguration.AddFlagSet(rootCommand.LocalFlags()) | ||
|
||
// add workflows as commands | ||
createCommandsForWorkflows(rootCommand, globalEngine) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: This should probably live in the cliv2 package, just considering the commend and the imports
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I do move it, I would also need to take the error chain iterator with it. Or maybe it's worth to relocate this error handling package somewhere out of the main package so it can be used around easier?