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 FprintStackTraceFromErr(w io.Writer, err error)
- func GetGID() uint64
- func Must(err error)
- func PrintStackTrace(w io.Writer)
- func PrintStackTraceFromErr(err error)
- func Recover(args ...interface{})
- func WithFileContext(e error, realFilename string, r io.Reader, matcher LineMatcherFn) (error, bool)
- func WithFileContextForFile(e error, realFilename, filename string, fs afero.Fs, matcher LineMatcherFn) (error, bool)
- func WithFileContextForFileDefault(err error, filename string, fs afero.Fs) error
- type ErrorContext
- type ErrorSender
- type ErrorWithFileContext
- type FileError
- func NewFileError(fileType string, offset, lineNumber, columnNumber int, err error) FileError
- func ToFileError(fileType string, err error) FileError
- func ToFileErrorWithLineNumber(fe FileError, lineNumber int) FileError
- func ToFileErrorWithOffset(fe FileError, offset int) FileError
- func UnwrapFileError(err error) FileError
- type LineMatcher
- type LineMatcherFn
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 SimpleLineMatcher = func(m LineMatcher) bool {
return m.Position.LineNumber == m.LineNumber
}
SimpleLineMatcher simply matches by line number.
Functions ¶
func FprintStackTraceFromErr ¶ added in v0.63.0
FprintStackTraceFromErr prints the error's stack trace to w.
func GetGID ¶ added in v0.63.0
func GetGID() uint64
Get the current goroutine id. Used only for debugging.
func PrintStackTrace ¶
PrintStackTrace prints the current stacktrace to w.
func PrintStackTraceFromErr ¶ added in v0.63.0
func PrintStackTraceFromErr(err error)
PrintStackTraceFromErr prints the error's stack trace to stdoud.
func Recover ¶ added in v0.56.0
func Recover(args ...interface{})
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 WithFileContext ¶
func WithFileContext(e error, realFilename string, r io.Reader, matcher LineMatcherFn) (error, bool)
WithFileContextForFile will try to add a file context with lines matching the given matcher. If no match could be found, the original error is returned with false as the second return value.
func WithFileContextForFile ¶
func WithFileContextForFile(e error, realFilename, filename string, fs afero.Fs, matcher LineMatcherFn) (error, bool)
WithFileContextForFile will try to add a file context with lines matching the given matcher. If no match could be found, the original error is returned with false as the second return value.
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 lexer to use for syntax highlighting. // https://gohugo.io/content-management/syntax-highlighting/#list-of-chroma-highlighting-languages ChromaLexer string // contains filtered or unexported fields }
ErrorContext contains contextual information about an error. This will typically be the lines surrounding some problem in a file.
func (ErrorContext) Position ¶
func (e ErrorContext) Position() text.Position
Position returns the text position of this error.
type ErrorSender ¶ added in v0.65.0
type ErrorSender interface {
SendError(err error)
}
ErrorSender is a, typically, non-blocking error handler.
type ErrorWithFileContext ¶
type ErrorWithFileContext struct { ErrorContext // contains filtered or unexported fields }
ErrorWithFileContext is an error with some additional file context related to that error.
func UnwrapErrorWithFileContext ¶
func UnwrapErrorWithFileContext(err error) *ErrorWithFileContext
UnwrapErrorWithFileContext tries to unwrap an ErrorWithFileContext from err. It returns nil if this is not possible.
func (*ErrorWithFileContext) Cause ¶
func (e *ErrorWithFileContext) Cause() error
func (*ErrorWithFileContext) Error ¶
func (e *ErrorWithFileContext) Error() string
type FileError ¶
type FileError interface { error text.Positioner // A string identifying the type of file, e.g. JSON, TOML, markdown etc. Type() string }
FileError represents an error when handling a file: Parsing a config file, execute a template etc.
func NewFileError ¶
NewFileError creates a new FileError.
func ToFileError ¶
ToFileError will convert the given error to an error supporting the FileError interface.
func ToFileErrorWithLineNumber ¶
ToFileErrorWithOffset will return a new FileError with the given line number.
func ToFileErrorWithOffset ¶
ToFileErrorWithOffset will return a new FileError with a line number with the given offset from the original.
func UnwrapFileError ¶
UnwrapFileError tries to unwrap a FileError from err. It returns nil if this is not possible.
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) bool
LineMatcherFn is used to match a line with an error.