1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2025-12-23 22:11:10 +02:00
Files
imgproxy/errctx/text_error.go
Victor Sokolov 69c7d2f117 IMG-76: new linter config & fixes (#1587)
* IMG-76: new linter config & fixes

* Upgrade golangci-lint to 2.7.2
2025-12-10 13:46:22 +01:00

28 lines
701 B
Go

package errctx
// TextError is an implementation of [Error] that holds a simple text message.
//
// When implementing a custom error type that does not wrap another error,
// embed [TextError] to provide standard behavior.
type TextError struct {
*ErrorContext
msg string
}
// NewTextError creates a new [TextError] with the given message and options.
func NewTextError(msg string, stackSkip int, opts ...Option) *TextError {
return &TextError{
msg: msg,
ErrorContext: newErrorContext(stackSkip+1, opts...),
}
}
// Error returns the error message with prefix if set.
func (e *TextError) Error() string {
if len(e.prefix) > 0 {
return e.prefix + ": " + e.msg
}
return e.msg
}