herrors

package
v0.54.0 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2019 License: Apache-2.0 Imports: 13 Imported by: 40

Documentation

Overview

Package errors 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")

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 FprintStackTrace

func FprintStackTrace(w io.Writer, err error)

FprintStackTrace prints the error's stack trace to w.

func PrintStackTrace

func PrintStackTrace(err error)

PrintStackTrace prints the error's stack trace to stdoud.

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