Help us shape the future of Go! Take the 2026 Go Developer Survey

helpers

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetResult

func GetResult[T any](pass *analysis.Pass, analyzer *analysis.Analyzer) (T, error)

GetResult returns the result of the analyzer.

func WrapRun

func WrapRun[T any](f func(*analysis.Pass) (T, error)) func(*analysis.Pass) (any, error)

WrapRun wraps the run function of an analyzer to: (1) convert the return type to Result[T] and put the error in the Result[T].Err field in order to _not_ stop the analysis and let upper-level analyzer to decide what to do. (2) recover from a panic and convert it to an error with stack traces for easier debugging. This is to ensure that NilAway _never_ panics during the analysis. Moreover, it also wraps the error from the sub-analyzer with the name of the analyzer to make it easier to identify the source of the error.

Types

type Result

type Result[T any] struct {
	// Res is the actual result from the sub-analyzer.
	Res T
	// Err is the optional error from the sub-analyzer.
	Err error
}

Result is the result struct for the sub-analyzers where the actual result is accompanied by an optional error.

Jump to

Keyboard shortcuts

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