Back to godoc.org

Package herrors

v0.74.3
Latest Go to latest

The latest major version is .

Published: Jul 23, 2020 | License: Apache-2.0 | Module: github.com/gohugoio/hugo

Overview

Package herrors contains common Hugo errors and error related utilities.

Package herrors contains common Hugo errors and error related utilities.

Index

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

func FprintStackTraceFromErr(w io.Writer, err error)

FprintStackTraceFromErr prints the error's stack trace to w.

func GetGID

func GetGID() uint64

Get the current goroutine id. Used only for debugging.

func PrintStackTrace

func PrintStackTrace(w io.Writer)

PrintStackTrace prints the current stacktrace to w.

func PrintStackTraceFromErr

func PrintStackTraceFromErr(err error)

PrintStackTraceFromErr prints the error's stack trace to stdoud.

func Recover

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.

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

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

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

NewFileError creates a new FileError.

func ToFileError

func ToFileError(fileType string, err error) FileError

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

func ToFileErrorWithLineNumber

func ToFileErrorWithLineNumber(fe FileError, lineNumber int) FileError

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

func ToFileErrorWithOffset

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

func UnwrapFileError(err error) FileError

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.

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier