diagnostics

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2024 License: MPL-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Diagnostic

type Diagnostic interface {

	// Severity returns the severity of the diagnostic.
	Severity() Severity

	// Summary returns a short summary of the diagnostic.
	Summary() string

	// Detail returns a detailed description of the diagnostic. This should be considered optional.
	Detail() string

	// Metadata returns additional metadata about the diagnostic. This can be used to provide additional context about the
	// diagnostic.
	Metadata() map[string]interface{}

	// Error returns the diagnostic as an error. The provided severity is used to determine which level of severity is
	// considered an error. For example, if the severity is SeverityError, then only errors should return an error here
	// with SeverityInfo and SeverityWarning returning nil.
	Error(severity Severity) error
}

Diagnostic represents a diagnostic message. This is an advanced kind of error that can be used to provide additional information about a problem. It can be used to provide more context about an error, warning, or information message.

type DiagnosticBuilder

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

DiagnosticBuilder is a builder for creating diagnostics.

func Error

func Error(summary string) *DiagnosticBuilder

Error creates a new diagnostic with the error severity.

func Info

func Info(summary string) *DiagnosticBuilder

Info creates a new diagnostic with the info severity.

func Warning

func Warning(summary string) *DiagnosticBuilder

Warning creates a new diagnostic with the warning severity.

func (*DiagnosticBuilder) AddAllMetadata

func (b *DiagnosticBuilder) AddAllMetadata(metadata map[string]interface{}) *DiagnosticBuilder

AddAllMetadata adds multiple metadata entries to the diagnostic.

func (*DiagnosticBuilder) AddMetadata

func (b *DiagnosticBuilder) AddMetadata(key string, value interface{}) *DiagnosticBuilder

AddMetadata adds metadata to the diagnostic.

func (*DiagnosticBuilder) Build

func (b *DiagnosticBuilder) Build() Diagnostic

Build creates the diagnostic.

func (*DiagnosticBuilder) Detail

func (b *DiagnosticBuilder) Detail(detail string) *DiagnosticBuilder

Detail sets the detail of the diagnostic.

func (*DiagnosticBuilder) SetErrorCode

func (b *DiagnosticBuilder) SetErrorCode(code errors.ErrorCode) *DiagnosticBuilder

SetErrorCode sets the error code of the diagnostic via the metadata.

type Diagnostics

type Diagnostics []Diagnostic

func (Diagnostics) Error

func (d Diagnostics) Error(incl Severity) error

Error returns an error if any of the diagnostics are of the provided severity or higher.

func (Diagnostics) Filter

func (d Diagnostics) Filter(severity Severity) Diagnostics

Filter returns a new Diagnostics instance with only the diagnostics that match the provided severity.

func (Diagnostics) Match

func (d Diagnostics) Match(severity Severity) bool

Match returns true if any of the diagnostics match either the provider severity or one of higher precedence. For example diags.Match(SeverityWarning) will return true if any of the diagnostics are SeverityWarning or SeverityError.

func (Diagnostics) Severity

func (d Diagnostics) Severity() Severity

Severity returns the highest severity of all the diagnostics.

type Severity

type Severity int
const (
	SeverityUnknown Severity = iota
	SeverityInfo
	SeverityWarning
	SeverityError
)

func MergeSeverities

func MergeSeverities(severities ...Severity) Severity

MergeSeverities returns the highest severity of the given severities.

func (Severity) Merge

func (s Severity) Merge(other Severity) Severity

Merge returns the highest severity of the two.

func (Severity) String

func (s Severity) String() string

Jump to

Keyboard shortcuts

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