Help us shape the future of Go! Take the 2026 Go Developer Survey

diag

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package diag defines diagnostics: user-facing problems found in files, settings or the workspace. Diagnostics carry a stable code and arguments rather than prose, so each application can render them through its own translation catalogue. English() is the default catalogue.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExcerptAt

func ExcerptAt(src []byte, pos Position) []string

ExcerptAt is the source line at pos and, when pos has a column, a caret line under it. Tabs are widened and invisible characters made visible, and the caret accounts for both. Columns count runes from 1. A position outside src gives nil.

func Invisible

func Invisible(r rune) bool

Invisible reports characters that show as nothing (or as a space) but change a value; excerpts show them as ⟨U+XXXX⟩.

Types

type Catalogue

type Catalogue interface {
	Message(d Diagnostic) (message, hint string)
}

Catalogue renders diagnostics as human-readable text.

func English

func English() Catalogue

English returns the default English catalogue.

type Code

type Code string

Code identifies a kind of diagnostic, e.g. "FLW-REF-001".

const (
	CodeYAMLSyntax       Code = "FLW-YAML-001"
	CodeYAMLUnknownKey   Code = "FLW-YAML-002"
	CodeYAMLDuplicateKey Code = "FLW-YAML-003"
	CodeYAMLType         Code = "FLW-YAML-004"
	CodeYAMLEmpty        Code = "FLW-YAML-005"

	CodeFormatTooNew  Code = "FLW-FMT-001"
	CodeFormatMissing Code = "FLW-FMT-002"

	CodeFileUnrecognised Code = "FLW-FILE-001"
	CodeFileUnreadable   Code = "FLW-FILE-002"

	CodeIDDuplicate Code = "FLW-ID-001"
	CodeIDInvalid   Code = "FLW-ID-002"
	CodeIDMissing   Code = "FLW-ID-003"

	CodeVersionInvalid       Code = "FLW-VER-001"
	CodeVersionDuplicate     Code = "FLW-VER-002"
	CodeVersionDefaultAbsent Code = "FLW-VER-003"
	CodeVersionPinnedAbsent  Code = "FLW-VER-004"
	CodeVersionNone          Code = "FLW-VER-005"

	CodeRefUnknownRequest Code = "FLW-REF-001"
	CodeRefUnknownFlow    Code = "FLW-REF-002"
	CodeRefUndeclared     Code = "FLW-REF-003"
	CodeRefNotMounted     Code = "FLW-REF-004"
	CodeRefStalePath      Code = "FLW-REF-005"

	CodeNodeUnknownType  Code = "FLW-NODE-001"
	CodeNodeDuplicateID  Code = "FLW-NODE-002"
	CodeNodeNeedsSibling Code = "FLW-NODE-003"
	CodeNodeMissingField Code = "FLW-NODE-004"
	CodeNodeParam        Code = "FLW-NODE-005"
	CodeNodeGoto         Code = "FLW-NODE-006"
	CodeNodeWriteClash   Code = "FLW-NODE-007"
	CodeNodeSubflowInput Code = "FLW-NODE-008"
	CodeNodeUnresolved   Code = "FLW-NODE-009"
	CodeNodeContract     Code = "FLW-NODE-010"
	CodeNodeAttach       Code = "FLW-NODE-011"
	CodeNodeRemovedType  Code = "FLW-NODE-012"

	CodeImportUnmapped  Code = "FLW-IMPORT-001"
	CodeImportInvalid   Code = "FLW-IMPORT-002"
	CodeImportExists    Code = "FLW-IMPORT-003"
	CodeImportSyntax    Code = "FLW-IMPORT-004"
	CodeImportSkipped   Code = "FLW-IMPORT-005"
	CodeImportSensitive Code = "FLW-IMPORT-006"
	CodeImportKeptEdit  Code = "FLW-IMPORT-007"
	CodeImportNoOpID    Code = "FLW-IMPORT-008"

	CodeMermaidPlaceholder Code = "FLW-MERMAID-001"
	CodeMermaidCycle       Code = "FLW-MERMAID-002"
	CodeArazzoDrift        Code = "FLW-ARAZZO-001"
	CodeArazzoCustom       Code = "FLW-ARAZZO-002"
	CodeArazzoLimit        Code = "FLW-ARAZZO-003"

	CodeSchemaRequest  Code = "FLW-SCHEMA-001"
	CodeSchemaResponse Code = "FLW-SCHEMA-002"
	CodeSchemaUpdated  Code = "FLW-SCHEMA-003"
	CodeSchemaMessage  Code = "FLW-SCHEMA-004"

	CodeAsyncProtocol Code = "FLW-ASYNC-001"
	CodeAsyncAction   Code = "FLW-ASYNC-002"
	CodeAsyncBinding  Code = "FLW-ASYNC-003"
	CodeAsyncServer   Code = "FLW-ASYNC-004"
	CodeAsyncTimeout  Code = "FLW-ASYNC-005"
	CodeAsyncConn     Code = "FLW-ASYNC-006"
	CodeAsyncConnName Code = "FLW-ASYNC-007"

	CodeGRPCRequest Code = "FLW-GRPC-001"
	CodeGRPCMethod  Code = "FLW-GRPC-002"
	CodeGRPCProto   Code = "FLW-GRPC-003"
	CodeGRPCBody    Code = "FLW-GRPC-004"
	CodeGRPCStatus  Code = "FLW-GRPC-005"
	CodeGRPCField   Code = "FLW-GRPC-006"

	CodeDatasetRequest Code = "FLW-DATA-001"
	CodeDatasetQuery   Code = "FLW-DATA-002"
	CodeDatasetTimeout Code = "FLW-DATA-003"

	CodeOutcome Code = "FLW-OUT-001"

	CodeExportLossy Code = "FLW-EXPORT-001"
	CodeExportValue Code = "FLW-EXPORT-002"

	CodeServeSchedule     Code = "FLW-SERVE-001"
	CodeServeScheduleFlow Code = "FLW-SERVE-002"

	CodeBlueprintParamType   Code = "FLW-BP-001"
	CodeBlueprintParamName   Code = "FLW-BP-002"
	CodeBlueprintRef         Code = "FLW-BP-003"
	CodeBlueprintParamUnused Code = "FLW-BP-004"
	CodeBlueprintUse         Code = "FLW-BP-005"
	CodeBlueprintNotFound    Code = "FLW-BP-006"
	CodeBlueprintAmbiguous   Code = "FLW-BP-007"

	CodeAuthInvalid Code = "FLW-AUTH-001"

	CodeOverlayInvalid    Code = "FLW-OVL-001"
	CodeOverlayNotFound   Code = "FLW-OVL-002"
	CodeOverlayNotFitting Code = "FLW-OVL-003"
	CodeOverlayDrift      Code = "FLW-OVL-004"
	CodeOverlayName       Code = "FLW-OVL-005"

	CodeWriteDropsComments Code = "FLW-WRITE-001"
	CodeWriteRequestPath   Code = "FLW-WRITE-002"
	CodeWriteEditNone      Code = "FLW-WRITE-003"
	CodeWriteEditLabel     Code = "FLW-WRITE-004"

	CodeContractBroken  Code = "FLW-CONTRACT-001"
	CodeContractInput   Code = "FLW-CONTRACT-002"
	CodeContractExample Code = "FLW-CONTRACT-003"

	CodeFlowOption    Code = "FLW-FLOW-001"
	CodeFlowNotFound  Code = "FLW-FLOW-002"
	CodeFlowAmbiguous Code = "FLW-FLOW-003"
	CodeFlowTagEmpty  Code = "FLW-FLOW-004"

	CodeCycleNeeds   Code = "FLW-CYC-001"
	CodeCycleSubflow Code = "FLW-CYC-002"

	CodeLintWhitespace Code = "FLW-LINT-001"
	CodeLintControl    Code = "FLW-LINT-002"
	CodeLintInvisible  Code = "FLW-LINT-003"

	CodeWSMissing           Code = "FLW-WS-001"
	CodeWSAlreadyMounted    Code = "FLW-WS-002"
	CodeWSNotCollection     Code = "FLW-WS-003"
	CodeWSManyCollections   Code = "FLW-WS-004"
	CodeWSUnknownCollection Code = "FLW-WS-005"

	CodeSettingUnknown    Code = "FLW-SET-001"
	CodeSettingInvalid    Code = "FLW-SET-002"
	CodeSettingWrongLayer Code = "FLW-SET-003"

	CodeTemplateUndefined Code = "FLW-TPL-001"
	CodeTemplateSyntax    Code = "FLW-TPL-002"
	CodeTemplateEmpty     Code = "FLW-TPL-003"
	CodeTemplateGenerator Code = "FLW-TPL-004"

	// Diagnostic code names, not credentials (gosec G101 matches "Secret").
	CodeSecretMissing         Code = "FLW-SEC-001" //nolint:gosec // see above
	CodeSecretLocked          Code = "FLW-SEC-002" //nolint:gosec // see above
	CodeSecretUndeclared      Code = "FLW-SEC-003" //nolint:gosec // see above
	CodeSecretFromEnvironment Code = "FLW-SEC-004" //nolint:gosec // see above

	CodeRequestNotFound    Code = "FLW-REQ-001"
	CodeRequestAmbiguous   Code = "FLW-REQ-002"
	CodeRequestFileOutside Code = "FLW-REQ-003"
	CodeRequestEnvUnknown  Code = "FLW-REQ-004"
	CodeRequestHeader      Code = "FLW-REQ-005"
	CodeRequestFileRead    Code = "FLW-REQ-006"
	CodeRequestExampleName Code = "FLW-REQ-007"
	CodeRequestEnvExtends  Code = "FLW-REQ-008"
	CodeRequestMethod      Code = "FLW-REQ-009"
	CodeRequestMethodCase  Code = "FLW-REQ-010"

	CodeRunAssertFailed   Code = "FLW-RUN-001"
	CodeRunAssertWarning  Code = "FLW-RUN-002"
	CodeRunNodeType       Code = "FLW-RUN-003"
	CodeRunSetTarget      Code = "FLW-RUN-004"
	CodeRunExtractEmpty   Code = "FLW-RUN-005"
	CodeRunHookDepth      Code = "FLW-RUN-006"
	CodeRunNodeTimeout    Code = "FLW-RUN-007"
	CodeRunTillLimit      Code = "FLW-RUN-008"
	CodeRunInputMissing   Code = "FLW-RUN-009"
	CodeRunInputUnknown   Code = "FLW-RUN-010"
	CodeRunCalcNumber     Code = "FLW-RUN-011"
	CodeRunBatchOver      Code = "FLW-RUN-012"
	CodeRunExtractNoResp  Code = "FLW-RUN-013"
	CodeRunDigestTarget   Code = "FLW-RUN-014"
	CodeRunHandled        Code = "FLW-RUN-015"
	CodeRunBackground     Code = "FLW-RUN-016"
	CodeRunFileName       Code = "FLW-RUN-017"
	CodeRunSaveStatus     Code = "FLW-RUN-018"
	CodeRunNoBranchOK     Code = "FLW-RUN-019"
	CodeRunWriteFailed    Code = "FLW-RUN-020"
	CodeRunStopped        Code = "FLW-RUN-021"
	CodeRunSkipRead       Code = "FLW-RUN-022"
	CodeRunAssertNoSchema Code = "FLW-RUN-023"
	CodeRunFuzzFailed     Code = "FLW-RUN-024"
	CodeRunNotProblem     Code = "FLW-RUN-025"
	CodeRunNoResponse     Code = "FLW-RUN-026"
	CodeRunDeprecated     Code = "FLW-RUN-027"

	CodeHTTPFailed  Code = "FLW-HTTP-001"
	CodeHTTPTimeout Code = "FLW-HTTP-002"

	CodeCycleHooks Code = "FLW-CYC-003"
)

Diagnostic codes. Codes are stable identifiers: never renumber or reuse one, because users search for them and catalogues are keyed by them.

func Codes

func Codes() []Code

Codes returns every diagnostic code.

type Diagnostic

type Diagnostic struct {
	Code     Code
	Severity Severity
	Location
	Args    map[string]string
	Related []Location
	// Excerpt is the source around Pos (see ExcerptAt), for inputs that
	// are not collection files: imported documents and pasted text.
	Excerpt []string
}

Diagnostic is one user-facing problem.

func New

func New(c Code, loc Location, args map[string]string) Diagnostic

New builds a diagnostic with the code's default severity.

type LineIndex

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

LineIndex converts many offsets of one source to positions without rescanning it: PositionAt in a loop is quadratic on large inputs, and so is counting columns from the line start on a long (minified) line. It remembers the last position, so increasing offsets cost only the text between them. Not safe for concurrent use.

func NewLineIndex

func NewLineIndex(src []byte) *LineIndex

NewLineIndex indexes src's line starts.

func (*LineIndex) Position

func (x *LineIndex) Position(offset int) Position

Position is PositionAt(src, offset).

type List

type List []Diagnostic

List is a set of diagnostics.

func (List) Err

func (l List) Err() error

Err returns nil unless the list has errors, in which case it returns a *ListError carrying the whole list.

func (List) HasErrors

func (l List) HasErrors() bool

HasErrors reports whether any diagnostic is an error.

func (List) Sorted

func (l List) Sorted() List

Sorted returns a copy ordered by file, line, column and code.

type ListError

type ListError struct{ List List }

ListError lets diagnostics travel through APIs that return error.

func (*ListError) Error

func (e *ListError) Error() string

type Location

type Location struct {
	File string
	Path string
	Pos  Position
}

Location points at a place in a file. Path is a YAML path such as "$.nodes[2].needs[0]"; empty means the whole file.

type Position

type Position struct{ Line, Column int }

Position is a 1-based line and column; zero means unknown.

func PositionAt

func PositionAt(src []byte, offset int) Position

PositionAt converts a byte offset in src to a line and rune column.

type Severity

type Severity int

Severity says whether a diagnostic blocks the operation.

const (
	SeverityError   Severity = 1
	SeverityWarning Severity = 2
)

Severities.

func DefaultSeverity

func DefaultSeverity(c Code) Severity

DefaultSeverity returns the severity a code carries unless a caller overrides it. Unknown codes are errors.

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