hugo: github.com/gohugoio/hugo/common/herrors Index | Files

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

Package Files

error_locator.go errors.go file_error.go line_number_extractors.go

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.

func FprintStackTraceFromErr Uses

func FprintStackTraceFromErr(w io.Writer, err error)

FprintStackTraceFromErr prints the error's stack trace to w.

func GetGID Uses

func GetGID() uint64

Get the current goroutine id. Used only for debugging.

func PrintStackTrace Uses

func PrintStackTrace(w io.Writer)

PrintStackTrace prints the current stacktrace to w.

func PrintStackTraceFromErr Uses

func PrintStackTraceFromErr(err error)

PrintStackTraceFromErr prints the error's stack trace to stdoud.

func Recover Uses

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 Uses

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 Uses

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.

type ErrorContext Uses

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 Uses

func (e ErrorContext) Position() text.Position

Position returns the text position of this error.

type ErrorSender Uses

type ErrorSender interface {
    SendError(err error)
}

ErrorSender is a, typically, non-blocking error handler.

type ErrorWithFileContext Uses

type ErrorWithFileContext struct {
    ErrorContext
    // contains filtered or unexported fields
}

ErrorWithFileContext is an error with some additional file context related to that error.

func UnwrapErrorWithFileContext Uses

func UnwrapErrorWithFileContext(err error) *ErrorWithFileContext

UnwrapErrorWithFileContext tries to unwrap an ErrorWithFileContext from err. It returns nil if this is not possible.

func (*ErrorWithFileContext) Cause Uses

func (e *ErrorWithFileContext) Cause() error

func (*ErrorWithFileContext) Error Uses

func (e *ErrorWithFileContext) Error() string

type FileError Uses

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 Uses

func NewFileError(fileType string, offset, lineNumber, columnNumber int, err error) FileError

NewFileError creates a new FileError.

func ToFileError Uses

func ToFileError(fileType string, err error) FileError

ToFileError will convert the given error to an error supporting the FileError interface.

func ToFileErrorWithLineNumber Uses

func ToFileErrorWithLineNumber(fe FileError, lineNumber int) FileError

ToFileErrorWithOffset will return a new FileError with the given line number.

func ToFileErrorWithOffset Uses

func ToFileErrorWithOffset(fe FileError, offset int) FileError

ToFileErrorWithOffset will return a new FileError with a line number with the given offset from the original.

func UnwrapFileError Uses

func UnwrapFileError(err error) FileError

UnwrapFileError tries to unwrap a FileError from err. It returns nil if this is not possible.

type LineMatcher Uses

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 Uses

type LineMatcherFn func(m LineMatcher) bool

LineMatcherFn is used to match a line with an error.

Package herrors imports 16 packages (graph) and is imported by 81 packages. Updated 2020-04-06. Refresh now. Tools for package owners.