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
Sergei Aleksandrovich e33254005d Refactored errors (#1578)
* Refactored errors

* Make monitoring and errorreport accept `errctx.Error` instead of `error`

* Add server.Error; Remove category from errctx; Make HTTP handlers respond with *server.Error

* Remove stackSkip from errctx.Wrap; Add errctx.WrapWithStackSkip
2025-11-20 01:26:21 +06:00

27 lines
700 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 {
msg string
*ErrorContext
}
// 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
}