Documentation
¶
Overview ¶
The errors package provides a custom error type and utilities used when performing recursive analysis of kitebuilder and proute apis.
The error type will provide context about what depth and what specific component of the API yielded the error, and the printing utilities assist in graphically representing the errors with corresponding nested depth.
Usage
import errors2 "github.com/assetnote/kiterunner/pkg/errors" ... if err := inAPI.EncodeStringSlice(output); err != nil { var merr *multierror.Error if errors.As(err, &merr) { for _, v := range merr.Errors { errors2.PrintError(v, 0) } } else { return fmt.Errorf("converting to txt output error: %w", err) } }
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PrintError ¶
PrintError will attempt to traverse the nested error and recursively print out any nested ParserErrors found If a multierror.Error is found, we will recurisvely print out each error found
Types ¶
type ParserError ¶
type ParserError struct { ID string // ID corresponds to the KSUID for the API allowing you to backref which API the error came from Method string // Method corresponds to the method for the request at the top level of the API Route string // Route corresponds to the route for the request RawJSON []byte // RawJSON optionally can include the raw json for the component if there was a JSON parsing error Err error // Err includes the error. If this is a wrapped error, then Error() will not print out this field Context string // Context is an arbitrary context field that you can use to add helpful text explaining the error }
ParserError encapsulates the contextual error relating to parsing an API schema The fields can be arbitrarily used to represent whatever information you wish
func (*ParserError) Error ¶
func (p *ParserError) Error() string
Error will return the string representation of the error. If the error is wrapped, we omit printing the wrapped error, allowing the user to determine how to display the wrapped error.
func (*ParserError) LogError ¶
func (p *ParserError) LogError(depth int)
LogError will log to Debug() the context surrounding the error. the depth argument modifies the indentation depth of the pretty printed error If RawJSON is included, we will add the RawJSON to the logging