herrors

package
v0.82.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 21, 2021 License: Apache-2.0 Imports: 16 Imported by: 40

Documentation

Overview

Package herrors contains common Hugo errors and error related utilities.

Package herrors contains common Hugo errors and error related utilities.

Index

Constants

This section is empty.

Variables

View Source
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.

View Source
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

func FprintStackTraceFromErr(w io.Writer, err error)

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

func PrintStackTrace(w io.Writer)

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

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL