analysishelper

package
v0.0.0-...-f3f320c Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: Apache-2.0 Imports: 3 Imported by: 10

Documentation

Overview

Package analysishelper provides helper functions for the `go/analysis` package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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