diag

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2022 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package diag implements a traditional multi-level diagnostic system compatible with the Go error interface.

The diag package implements four levels of message;

  • Fatal: diagnostics that immediately terminate the program, for use when a program cannot make progress at all or a problem is so severe that no output should be produced.
  • Errors: diagnostics that lead to program exit without output, but are sufficiently recoverable that further useful diagnostic output remains possible before exiting.
  • Warnings: diagnostics that indicate something is not advisable, but also not an error.
  • Info: diagnostics that provide informational messages to the user, such as copyright notices, versions information, and the like.

When printed, or returned as an error value, diagnostics are organized in sorted by input position. If a sorting function is not explicitly provided, position strings are assumed to take the form

filename:line:column

Diagnostic messages (type Diag) are organized into groups (type Diags). Groups can be merged using the Diags.With() message. This is useful primarily in compiler-like applications that implement rollback with roll-forward.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Diag

type Diag = *diag // Export as a heap-allocated type

func (Diag) String

func (d Diag) String() string

Return a string represnting a specific diagnostic message.

type DiagKind

type DiagKind int
const (
	// Errors that are immediately fatal
	Fatal DiagKind = iota
	// Errors that terminate execution, typically at the end of the current
	// pass.
	Error
	// Warnings that do not terminate execution.
	Warning

	// Informational diagnostics that do not terminate execution.
	Info
)

func (DiagKind) String

func (i DiagKind) String() string

type Diags

type Diags = *diags // Export as a heap-allocated type

func New

func New() Diags

Return a new diagnostic group.

func (Diags) Add

func (c Diags) Add(where Position, kind DiagKind, msg string) Diags

Add a diagnostic with the specified location, severity, and message payload

func (Diags) AddError

func (c Diags) AddError(where Position, msg string) Diags

Record an error diagnostic at the specified location with the provided message.

func (Diags) AddFatal

func (c Diags) AddFatal(where Position, msg string) Diags

Issue a fatal diagnostic giving the specified location and message.

func (Diags) AddInfo

func (c Diags) AddInfo(where Position, msg string) Diags

Record an informational diagnostic at the specified location with the provided message.

func (Diags) AddWarn

func (c Diags) AddWarn(where Position, msg string) Diags

Record a warning diagnostic at the specified location with the provided message.

func (Diags) AsError

func (d Diags) AsError() error

Return a go error value or nil according to whether errors are present.

Note that warning and informational diagnostics are not considered errors for this purpose. This is contrary to the prevailing school of thought favored by the Go team.

func (Diags) Empty

func (d Diags) Empty() bool

func (Diags) Error

func (d Diags) Error() string

Implement the error.Error() interface, so that a diagnostic set can be returned as an error value.

func (Diags) String

func (d Diags) String() string

Return a string containing all diagnostics in the diagnostic group, sorted by the active sorting algorithm.

func (Diags) With

func (c Diags) With(d Diags) Diags

Return a fresh diagnostic group combining the diagnostics of two existing groups.

The sorting criteria of the receiver is used by the fresh diagnostic group.

type Position

type Position position.Position

Jump to

Keyboard shortcuts

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