Special error handling for appstudio format only
(noFail bool, prefix string, err error)
| 57 | |
| 58 | // Special error handling for appstudio format only |
| 59 | func appstudioErrorHandler(noFail bool, prefix string, err error) error { |
| 60 | // Output some json to stdout |
| 61 | applicationsnapshot.OutputAppstudioReport(applicationsnapshot.AppstudioReportForError(prefix, err)) |
| 62 | |
| 63 | // Beware we're effectively changing the meaning of the --no-fail flag here. |
| 64 | // Rather than being only about policy failures any more, we're extending |
| 65 | // it to also mean don't return a non-zero exit code for an error handled |
| 66 | // by this function. |
| 67 | if noFail { |
| 68 | // Still put the real error in stderr so there is some chance |
| 69 | // users can figure out what caused the problem |
| 70 | fmt.Fprintf(os.Stderr, "Error: %s: %s\n", prefix, err.Error()) |
| 71 | |
| 72 | // So the exit code is zero |
| 73 | return nil |
| 74 | } else { |
| 75 | // "Normal" behavior, return the formatted error |
| 76 | return fmt.Errorf("%s: %w", prefix, err) |
| 77 | } |
| 78 | } |
no test coverage detected