Improved Error Handling#74
Conversation
Reviewer's GuideThis PR overhauls error handling both in the library and CLI by introducing custom error types for wrapping, refining Cobra argument validation with a custom ExactArgs function, updating main’s error dispatch logic, and expanding and refactoring tests to assert precise stdout/stderr behavior—including new invalid ELF and recursive-file scenarios. ELF parsing error messages are also simplified. Sequence diagram for main error dispatch logic in CLIsequenceDiagram
participant main
participant rootCmd
participant os
participant snaggleError
main->>rootCmd: Execute()
alt err == nil
main->>os: Exit(0)
else errors.As(err, &snaggleError)
main->>os: Exit(1)
else
main->>rootCmd: UsageString()
main->>os: Exit(2)
end
Class diagram for new and updated error typesclassDiagram
class SnaggleError {
+string Src
+string Dst
+error err
+Error() string
+Unwrap() error
}
class InvocationError {
+string Path
+string Target
+error err
+Error() string
+Unwrap() error
}
SnaggleError --|> error
InvocationError --|> error
Class diagram for updated argument validation in CLIclassDiagram
class cobra_Command {
+Use string
+SilenceUsage bool
+DisableFlagsInUseLine bool
+Long string
+Args PositionalArgs
+RunE func(cmd, args) error
}
class ExactArgs {
+ExactArgs(n int) cobra.PositionalArgs
}
cobra_Command --> ExactArgs: uses
File-Level Changes
Assessment against linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #74 +/- ##
==========================================
- Coverage 75.36% 74.11% -1.26%
==========================================
Files 8 8
Lines 483 506 +23
==========================================
+ Hits 364 375 +11
- Misses 85 95 +10
- Partials 34 36 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Hey there - I've reviewed your changes - here's some feedback:
- Extract the repetitive CLI test setup and exit‐code/assertion logic into shared helper functions to reduce duplication and improve readability.
- In main.go the usage text is printed via println (stdout)—consider using PrintErr or fmt.Fprintln(os.Stderr, ...) so usage and errors go to stderr consistently.
- To make error matching with errors.Is more ergonomic, consider adding an Is method on InvocationError and SnaggleError or otherwise supporting error.Is in addition to errors.As.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Extract the repetitive CLI test setup and exit‐code/assertion logic into shared helper functions to reduce duplication and improve readability.
- In main.go the usage text is printed via println (stdout)—consider using PrintErr or fmt.Fprintln(os.Stderr, ...) so usage and errors go to stderr consistently.
- To make error matching with errors.Is more ergonomic, consider adding an Is method on InvocationError and SnaggleError or otherwise supporting error.Is in addition to errors.As.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Summary by Sourcery
Introduce structured error handling and improve CLI error reporting by wrapping ELF parsing errors in SnaggleError, returning InvocationError for invalid recursive usage, and implementing custom argument validation with ExactArgs. Update main to silence usage on error, initialize help/version flags, and distinguish exit codes for SnaggleError vs other errors. Revise ELF error formatting and synchronize tests with the new error types and message formats.
New Features:
Enhancements:
Tests: