errstack

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultWrappedFunctions = map[string][]string{
		"github.com/pkg/errors": {"New", "Errorf", "Wrap", "Wrapf", "WithStack"},
	}
	DefaultCleanFunctions = map[string][]string{
		"fmt":                   {"Errorf"},
		"errors":                {"New"},
		"github.com/pkg/errors": {"WithMessage", "WithMessagef"},
	}
	DefaultThreshold     = .25
	DefaultMaxStackDepth = 25
)

Functions

func New

func New(settings any) (register.LinterPlugin, error)

func NewAnalyzer

func NewAnalyzer(settings Settings) *analysis.Analyzer

Types

type Assignment

type Assignment struct {
	Stmt *ast.AssignStmt
	LPos int
	RPos int
}

type Ctx

type Ctx struct {
	Info *types.Info
	Fset *token.FileSet
}

func (*Ctx) Pos

func (c *Ctx) Pos(pos token.Pos) string

type ErrStack

type ErrStack struct {
	// contains filtered or unexported fields
}

func NewErrStack

func NewErrStack(settings Settings) *ErrStack

func (*ErrStack) Run

func (es *ErrStack) Run(pass *analysis.Pass) (any, error)

type Func

type Func struct {
	Pkg  *types.Package
	Name string
}

type FunctionInfo

type FunctionInfo map[string][]string

func (FunctionInfo) Contains

func (f FunctionInfo) Contains(ctx *Ctx, call *ast.CallExpr) bool

type Plugin

type Plugin struct {
	// contains filtered or unexported fields
}

func (*Plugin) BuildAnalyzers

func (p *Plugin) BuildAnalyzers() ([]*analysis.Analyzer, error)

func (*Plugin) GetLoadMode

func (p *Plugin) GetLoadMode() string

type Settings

type Settings struct {
	// WrappedFunctions - list of functions that are considered to wrap errors.
	// If you're using some fancy error wrapping library like github.com/pkg/errors,
	// you may want to add it to this list.
	// If you want to ignore some functions, simply don't add them to the list.
	WrappedFunctions FunctionInfo `mapstructure:"wrappedFunctions" yaml:"wrappedFunctions"`
	// CleanFunctions - list of functions that are considered to clean errors without stacktrace.
	CleanFunctions FunctionInfo `mapstructure:"cleanFunctions" yaml:"cleanFunctions"`
	// Threshold in percentage for the number of branches returning wrapped errors to be considered a violation.
	// Default value is 25%.
	// That means that if there are 3 sources of error that are non-wrapped and one that is wrapped, ErrStack will report an error.
	// On the other hand, if there are 4 wrapped sources and only one non-wrapped source, ErrStack will not report an error.
	Threshold float64 `mapstructure:"threshold" yaml:"threshold"`
	// MaxStackDepth - how many stack frames to check for before giving up.
	// May impact performance on large codebases and high value.
	// Default value is 25.
	MaxStackDepth int `mapstructure:"maxStackDepth" yaml:"maxStackDepth"`
}

func NewDefaultConfig

func NewDefaultConfig() Settings

Jump to

Keyboard shortcuts

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