package herrors
import "github.com/gohugoio/hugo/common/herrors"
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)
- func Unwrap(err error) error
- type ErrorContext
- type ErrorSender
- type FeatureNotAvailableError
- func (e *FeatureNotAvailableError) Error() string
- func (e *FeatureNotAvailableError) Is(target error) bool
- func (e *FeatureNotAvailableError) Unwrap() error
- 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
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 ¶
Cause returns the underlying error, that is, it unwraps errors until it finds one that does not implement the Unwrap method. For a shallow variant, see Unwrap.
func ContainsMatcher ¶
func ContainsMatcher(text string) func(m LineMatcher) int
ContainsMatcher is a line matcher that matches by line content.
func ImproveRenderErr ¶
ImproveRenderErr improves the error message for rendering errors.
func IsExist ¶
IsExist returns true if the error is a file exists error. Unlike os.IsExist, this also considers wrapped errors.
func IsFeatureNotAvailableError ¶
IsFeatureNotAvailableError returns true if the given error is or contains a FeatureNotAvailableError.
func IsNotExist ¶
IsNotExist returns true if the error is a file not found error. Unlike os.IsNotExist, this also considers wrapped errors.
func IsTimeoutError ¶
IsTimeoutError returns true if the given error is or contains a TimeoutError.
func Must ¶
func Must(err error)
Must panics if err != nil.
func PrintStackTrace ¶
PrintStackTrace prints the current stacktrace to w.
func Recover ¶
func Recover(args ...any)
Recover is a helper function that can be used to capture panics. Put this at the top of a method/function that crashes in a template:
defer herrors.Recover()
func Unwrap ¶
Unwrap returns the underlying error or itself if it does not implement Unwrap.
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 ¶
type ErrorSender interface { SendError(err error) }
ErrorSender is a, typically, non-blocking error handler.
type FeatureNotAvailableError ¶
type FeatureNotAvailableError struct { Cause error }
FeatureNotAvailableError is an error type used to signal that a feature is not available.
func (*FeatureNotAvailableError) Error ¶
func (e *FeatureNotAvailableError) Error() string
func (*FeatureNotAvailableError) Is ¶
func (e *FeatureNotAvailableError) Is(target error) bool
func (*FeatureNotAvailableError) Unwrap ¶
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 ¶
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 ¶
func NewFileErrorFromFileInErr(err error, fs afero.Fs, linematcher LineMatcherFn) FileError
func NewFileErrorFromFileInPos ¶
func NewFileErrorFromFileInPos(err error, pos text.Position, fs afero.Fs, linematcher LineMatcherFn) FileError
func NewFileErrorFromName ¶
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 ¶
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 ¶
UnwrapFileErrors tries to unwrap all FileError.
func UnwrapFileErrorsWithErrorContext ¶
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 ¶
TextSegmentError is an error with a text segment attached.
func (TextSegmentError) Error ¶
func (e TextSegmentError) Error() string
func (TextSegmentError) Unwrap ¶
func (e TextSegmentError) Unwrap() error
type TimeoutError ¶
func (*TimeoutError) Error ¶
func (e *TimeoutError) Error() string
func (*TimeoutError) Is ¶
func (e *TimeoutError) Is(target error) bool
type Unwrapper ¶
type Unwrapper interface { Unwrap() error }
Unwrapper can unwrap errors created with fmt.Errorf.
Source Files ¶
error_locator.go errors.go file_error.go line_number_extractors.go
- Version
- v0.144.2 (latest)
- Published
- Feb 19, 2025
- Platform
- linux/amd64
- Imports
- 19 packages
- Last checked
- 13 hours ago –
Tools for package owners.