Add config file support to CLI parser

Add -f/--config-file flag for loading YAML configs from local or remote sources. Fix error handling to return unmatched errors.
This commit is contained in:
2025-08-28 23:57:00 +04:00
parent 42335c1178
commit 29b85d5b83
9 changed files with 138 additions and 26 deletions

View File

@@ -55,7 +55,7 @@ func HandleError(err error, matchers ...ErrorMatcher) (bool, error) {
}
}
return false, nil // No matcher found
return false, err // No matcher found
}
// HandleErrorOrDie processes an error against a list of matchers and executes the appropriate handler.

View File

@@ -17,7 +17,7 @@ type CustomError struct {
Message string
}
func (e *CustomError) Error() string {
func (e CustomError) Error() string {
return fmt.Sprintf("custom error %d: %s", e.Code, e.Message)
}
@@ -91,16 +91,15 @@ func TestHandleError(t *testing.T) {
t.Run("HandleError with no matching handler", func(t *testing.T) {
err := errors.New("unhandled error")
handled, result := HandleError(err,
handled, _ := HandleError(err,
OnSentinelError(io.EOF, func(e error) error {
return nil
}),
OnCustomError(func(e *CustomError) error {
OnCustomError(func(e CustomError) error {
return nil
}),
)
assert.False(t, handled)
assert.NoError(t, result)
})
t.Run("HandleError with multiple matchers first match wins", func(t *testing.T) {
@@ -352,9 +351,8 @@ func TestErrorMatcherEdgeCases(t *testing.T) {
}
err := errors.New("test error")
handled, result := HandleError(err, matcher)
handled, _ := HandleError(err, matcher)
assert.False(t, handled)
assert.NoError(t, result)
})
t.Run("Handler that panics", func(t *testing.T) {