Skip to content

Commit

Permalink
Fix ierrors wrap order
Browse files Browse the repository at this point in the history
  • Loading branch information
muXxer committed Jan 24, 2024
1 parent 180e65c commit 9310d31
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions ierrors/ierrors_no_stacktrace.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func Errorf(format string, args ...any) error {
// Wrap adds a stacktrace to the error if there was no stacktrace
// in the error tree yet and if the build flag "stacktrace" is set.
func Wrap(err error, message string) error {
return fmt.Errorf("%w: %s", err, message)
return fmt.Errorf("%s: %w", message, err)
}

// Wrapf annotates an error with a message format specifier and arguments.
Expand All @@ -36,11 +36,11 @@ func Wrapf(err error, format string, args ...interface{}) error {
// check if the passed args also contain an error
for _, arg := range args {
if _, ok := arg.(error); ok {
return fmt.Errorf("%w: %w", err, fmt.Errorf(format, args...))
return fmt.Errorf("%w: %w", fmt.Errorf(format, args...), err)
}
}

return fmt.Errorf("%w: %s", err, fmt.Sprintf(format, args...))
return fmt.Errorf("%s: %w", fmt.Sprintf(format, args...), err)
}

// WithStack adds a stacktrace to the error if there was no stacktrace
Expand Down
6 changes: 3 additions & 3 deletions ierrors/ierrors_stacktrace.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func Errorf(format string, args ...any) error {
// Wrap adds a stacktrace to the error if there was no stacktrace
// in the error tree yet and if the build flag "stacktrace" is set.
func Wrap(err error, message string) error {
return ensureStacktraceUniqueness(fmt.Errorf("%w: %s", err, message))
return ensureStacktraceUniqueness(fmt.Errorf("%s: %w", message, err))
}

// Wrapf annotates an error with a message format specifier and arguments.
Expand All @@ -98,11 +98,11 @@ func Wrapf(err error, format string, args ...interface{}) error {
for _, arg := range args {
if _, ok := arg.(error); ok {
// wrap the other errors as well
return ensureStacktraceUniqueness(fmt.Errorf("%w: %w", err, fmt.Errorf(format, args...)))
return ensureStacktraceUniqueness(fmt.Errorf("%w: %w", fmt.Errorf(format, args...), err))
}
}

return ensureStacktraceUniqueness(fmt.Errorf("%w: %s", err, fmt.Sprintf(format, args...)))
return ensureStacktraceUniqueness(fmt.Errorf("%s: %w", fmt.Sprintf(format, args...), err))
}

// WithStack adds a stacktrace to the error if there was no stacktrace
Expand Down

0 comments on commit 9310d31

Please sign in to comment.