Documentation ¶
Overview ¶
Package herrors contains common Hugo errors and error related utilities.
Package herrors contains common Hugo errors and error related utilities.
Index ¶
- Variables
- func Cause(err error) error
- func ContainsMatcher(text string) func(m LineMatcher) int
- func ImproveRenderErr(inErr error) (outErr error)
- func IsExist(err error) bool
- func IsFeatureNotAvailableError(err error) bool
- func IsNotExist(err error) bool
- func IsTimeoutError(err error) bool
- func Must(err error)
- func PrintStackTrace(w io.Writer)
- func Recover(args ...any)
- type ErrorContext
- type ErrorSender
- type FeatureNotAvailableError
- type FileError
- func NewFileError(err error) FileError
- func NewFileErrorFromFile(err error, filename string, fs afero.Fs, linematcher LineMatcherFn) FileError
- func NewFileErrorFromFileInErr(err error, fs afero.Fs, linematcher LineMatcherFn) FileError
- func NewFileErrorFromFileInPos(err error, pos text.Position, fs afero.Fs, linematcher LineMatcherFn) FileError
- func NewFileErrorFromName(err error, name string) FileError
- func NewFileErrorFromPos(err error, pos text.Position) FileError
- func UnwrapFileError(err error) FileError
- func UnwrapFileErrors(err error) []FileError
- func UnwrapFileErrorsWithErrorContext(err error) []FileError
- type LineMatcher
- type LineMatcherFn
- type TextSegmentError
- type TimeoutError
- type Unwrapper
Constants ¶
This section is empty.
Variables ¶
var ErrFeatureNotAvailable = &FeatureNotAvailableError{Cause: errors.New("this feature is not available in your current Hugo version, see https://goo.gl/YMrWcn for more information")}
ErrFeatureNotAvailable denotes that a feature is unavailable.
We will, at least to begin with, make some Hugo features (SCSS with libsass) optional, and this error is used to signal those situations.
var NopLineMatcher = func(m LineMatcher) int {
return 1
}
NopLineMatcher is a matcher that always returns 1. This will effectively give line 1, column 1.
var OffsetMatcher = func(m LineMatcher) int { if m.Offset+len(m.Line) >= m.Position.Offset { return 0 } return -1 }
OffsetMatcher is a line matcher that matches by offset.
var SimpleLineMatcher = func(m LineMatcher) int {
if m.Position.LineNumber == m.LineNumber {
return 0
}
return -1
}
SimpleLineMatcher simply matches by line number.
Functions ¶
func Cause ¶ added in v0.99.0
Cause returns the underlying error or itself if it does not implement Unwrap.
func ContainsMatcher ¶ added in v0.112.0
func ContainsMatcher(text string) func(m LineMatcher) int
ContainsMatcher is a line matcher that matches by line content.
func ImproveRenderErr ¶ added in v0.128.0
ImproveRenderErr improves the error message for rendering errors.
func IsExist ¶ added in v0.140.0
IsExist returns true if the error is a file exists error. Unlike os.IsExist, this also considers wrapped errors.
func IsFeatureNotAvailableError ¶ added in v0.115.4
IsFeatureNotAvailableError returns true if the given error is or contains a FeatureNotAvailableError.
func IsNotExist ¶ added in v0.109.0
IsNotExist returns true if the error is a file not found error. Unlike os.IsNotExist, this also considers wrapped errors.
func IsTimeoutError ¶ added in v0.123.0
IsTimeoutError returns true if the given error is or contains a TimeoutError.
func PrintStackTrace ¶
PrintStackTrace prints the current stacktrace to w.
Types ¶
type ErrorContext ¶
type ErrorContext struct { // If a match will contain the matched line and up to 2 lines before and after. // Will be empty if no match. Lines []string // The position of the error in the Lines above. 0 based. LinesPos int // The position of the content in the file. Note that this may be different from the error's position set // in FileError. Position text.Position // The lexer to use for syntax highlighting. // https://gohugo.io/content-management/syntax-highlighting/#list-of-chroma-highlighting-languages ChromaLexer string }
ErrorContext contains contextual information about an error. This will typically be the lines surrounding some problem in a file.
type ErrorSender ¶ added in v0.65.0
type ErrorSender interface {
SendError(err error)
}
ErrorSender is a, typically, non-blocking error handler.
type FeatureNotAvailableError ¶ added in v0.115.4
type FeatureNotAvailableError struct {
Cause error
}
FeatureNotAvailableError is an error type used to signal that a feature is not available.
func (*FeatureNotAvailableError) Error ¶ added in v0.115.4
func (e *FeatureNotAvailableError) Error() string
func (*FeatureNotAvailableError) Is ¶ added in v0.115.4
func (e *FeatureNotAvailableError) Is(target error) bool
func (*FeatureNotAvailableError) Unwrap ¶ added in v0.115.4
func (e *FeatureNotAvailableError) Unwrap() error
type FileError ¶
type FileError interface { error // ErrorContext holds some context information about the error. ErrorContext() *ErrorContext text.Positioner // UpdatePosition updates the position of the error. UpdatePosition(pos text.Position) FileError // UpdateContent updates the error with a new ErrorContext from the content of the file. UpdateContent(r io.Reader, linematcher LineMatcherFn) FileError // SetFilename sets the filename of the error. SetFilename(filename string) FileError }
FileError represents an error when handling a file: Parsing a config file, execute a template etc.
func NewFileError ¶
NewFileError creates a new FileError that wraps err. It will try to extract the filename and line number from err.
func NewFileErrorFromFile ¶ added in v0.99.0
func NewFileErrorFromFile(err error, filename string, fs afero.Fs, linematcher LineMatcherFn) FileError
NewFileErrorFromFile is a convenience method to create a new FileError from a file.
func NewFileErrorFromFileInErr ¶ added in v0.99.0
func NewFileErrorFromFileInErr(err error, fs afero.Fs, linematcher LineMatcherFn) FileError
func NewFileErrorFromFileInPos ¶ added in v0.99.0
func NewFileErrorFromName ¶ added in v0.99.0
NewFileErrorFromName creates a new FileError that wraps err. The value for name should identify the file, the best being the full filename to the file on disk.
func NewFileErrorFromPos ¶ added in v0.99.0
NewFileErrorFromPos will use the filename and line number from pos to create a new FileError, wrapping err.
func UnwrapFileError ¶
UnwrapFileError tries to unwrap a FileError from err. It returns nil if this is not possible.
func UnwrapFileErrors ¶ added in v0.99.0
UnwrapFileErrors tries to unwrap all FileError.
func UnwrapFileErrorsWithErrorContext ¶ added in v0.99.0
UnwrapFileErrorsWithErrorContext tries to unwrap all FileError in err that has an ErrorContext.
type LineMatcher ¶
type LineMatcher struct { Position text.Position Error error LineNumber int Offset int Line string }
LineMatcher contains the elements used to match an error to a line
type LineMatcherFn ¶
type LineMatcherFn func(m LineMatcher) int
LineMatcherFn is used to match a line with an error. It returns the column number or 0 if the line was found, but column could not be determined. Returns -1 if no line match.
type TextSegmentError ¶ added in v0.112.0
TextSegmentError is an error with a text segment attached.
func (TextSegmentError) Error ¶ added in v0.112.0
func (e TextSegmentError) Error() string
func (TextSegmentError) Unwrap ¶ added in v0.112.0
func (e TextSegmentError) Unwrap() error
type TimeoutError ¶ added in v0.123.0
func (*TimeoutError) Error ¶ added in v0.123.0
func (e *TimeoutError) Error() string
func (*TimeoutError) Is ¶ added in v0.123.0
func (e *TimeoutError) Is(target error) bool