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 ¶
- type Diag
- type DiagKind
- type Diags
- func (c Diags) Add(where Position, kind DiagKind, msg string) Diags
- func (c Diags) AddError(where Position, msg string) Diags
- func (c Diags) AddFatal(where Position, msg string) Diags
- func (c Diags) AddInfo(where Position, msg string) Diags
- func (c Diags) AddWarn(where Position, msg string) Diags
- func (d Diags) AsError() error
- func (d Diags) Empty() bool
- func (d Diags) Error() string
- func (d Diags) String() string
- func (c Diags) With(d Diags) Diags
- type Position
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Diags ¶
type Diags = *diags // Export as a heap-allocated type
func (Diags) AddError ¶
Record an error diagnostic at the specified location with the provided message.
func (Diags) AddInfo ¶
Record an informational diagnostic at the specified location with the provided message.
func (Diags) AddWarn ¶
Record a warning diagnostic at the specified location with the provided message.
func (Diags) AsError ¶
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) Error ¶
Implement the error.Error() interface, so that a diagnostic set can be returned as an error value.