errstack

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultWrapperFunctions = []PkgFunctions{
		{Pkg: "github.com/pkg/errors", Names: []string{
			"New", "Errorf", "Wrap", "Wrapf", "WithStack",
		}},
	}
	DefaultCleanFunctions = []PkgFunctions{
		{Pkg: "github.com/pkg/errors", Names: []string{
			"WithMessage", "WithMessagef",
		}},
		{Pkg: "errors", Names: []string{
			"New", "Wrapf", "WithStack",
		}},
		{Pkg: "fmt", Names: []string{
			"Errorf",
		}},
	}
)

Functions

func New

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

func NewAnalyzer

func NewAnalyzer(settings Config) *analysis.Analyzer

Types

type Config added in v0.0.3

type Config struct {
	// WrapperFunctions - 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.
	WrapperFunctions []PkgFunctions `mapstructure:"wrapperFunctions" yaml:"wrapperFunctions"`
	// CleanFunctions - list of functions that are considered to clean errors without stacktrace.
	CleanFunctions []PkgFunctions `mapstructure:"cleanFunctions" yaml:"cleanFunctions"`
}

func NewDefaultConfig

func NewDefaultConfig() Config

type ErrStack

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

func NewErrStack

func NewErrStack(config Config) *ErrStack

func (*ErrStack) Run

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

type Function added in v0.1.0

type Function struct {
	Name       string                // Name of the function
	Node       ast.Node              // AST node of the function
	Block      *cfg.Block            // Control flow graph of the function
	Pos        token.Position        // Position of the function declaration
	IsWrapping bool                  // Is true if this function returns wrapped errors
	CalledBy   *List[token.Position] // Functions that call this function
	Pkg        string                // Package containing the function
	Pass       *Pass                 // Pass used to load the function
}

type List added in v0.1.0

type List[T comparable] struct {
	// contains filtered or unexported fields
}

func NewList added in v0.1.0

func NewList[T comparable](length, capacity int) *List[T]

func (*List[T]) AddUnique added in v0.1.0

func (l *List[T]) AddUnique(value T)

func (*List[T]) Clone added in v0.1.0

func (l *List[T]) Clone() []T

func (*List[T]) Len added in v0.1.0

func (l *List[T]) Len() int

func (*List[T]) Pop added in v0.1.0

func (l *List[T]) Pop() (value T)

func (*List[T]) Push added in v0.1.0

func (l *List[T]) Push(value T)

type Locked added in v0.1.0

type Locked[T any] struct {
	// contains filtered or unexported fields
}

func NewLocked added in v0.1.0

func NewLocked[T any](v T) *Locked[T]

func (*Locked[T]) Get added in v0.1.0

func (l *Locked[T]) Get() T

func (*Locked[T]) Set added in v0.1.0

func (l *Locked[T]) Set(v T)

type Map added in v0.1.0

type Map[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func NewMap added in v0.1.0

func NewMap[K comparable, V any](capacity int) *Map[K, V]

func (*Map[K, V]) Clone added in v0.1.0

func (m *Map[K, V]) Clone() map[K]V

func (*Map[K, V]) Delete added in v0.1.0

func (m *Map[K, V]) Delete(key K)

func (*Map[K, V]) Get added in v0.1.0

func (m *Map[K, V]) Get(key K) (value V, ok bool)

func (*Map[K, V]) Len added in v0.1.0

func (m *Map[K, V]) Len() int

func (*Map[K, V]) Set added in v0.1.0

func (m *Map[K, V]) Set(key K, value V)

type NodeInfo added in v0.1.0

type NodeInfo struct {
	Pass *Pass
	Node ast.Node
}

type Pass added in v0.1.0

type Pass struct {
	Fset      *token.FileSet
	TypesInfo *types.Info
	Files     []*ast.File
	ResultOf  map[*analysis.Analyzer]interface{}
}

func NewPass added in v0.1.0

func NewPass(analysisPass *analysis.Pass) *Pass

type PkgFunctions added in v0.1.0

type PkgFunctions struct {
	Pkg   string
	Names []string
}

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 []PkgFunctions
	CleanFunctions   []PkgFunctions
	GoRoot           string
	WorkDir          string
}

type Stack added in v0.1.0

type Stack[T comparable] []T

func (*Stack[T]) AddUnique added in v0.1.0

func (s *Stack[T]) AddUnique(v ...T) *Stack[T]

func (*Stack[T]) Pop added in v0.1.0

func (s *Stack[T]) Pop() *T

func (*Stack[T]) Push added in v0.1.0

func (s *Stack[T]) Push(v ...T) *Stack[T]

Jump to

Keyboard shortcuts

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