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 GetGID() uint64
- func Must(err error)
- func PrintStackTrace(w io.Writer)
- func Recover(args ...any)
- type ErrorContext
- type ErrorSender
- 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 Unwrapper
Constants ¶
This section is empty.
Variables ¶
var ErrFeatureNotAvailable = 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 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 ¶
type ErrorSender interface {
SendError(err error)
}
ErrorSender is a, typically, non-blocking error handler.
type FileError ¶
type FileError interface { error // ErroContext 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 }
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 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 determinde. Returns -1 if no line match.