yum/yaml/diagnostic
Typed diagnostics produced while resolving YAML.
Diagnostics describe semantic YAML issues such as duplicate mapping keys,
unknown aliases, invalid directives, and invalid tags. Parse a document,
resolve it with yum/yaml.resolve, then inspect the
diagnostics kept on the resolved document.
import gleam/list
import yum/yaml
import yum/yaml/diagnostic
pub fn example() {
let assert Ok(document) = yaml.parse("
name: one
name: two
")
let assert Ok(document) = yaml.resolve(document)
let messages =
document
|> yaml.diagnostics()
|> list.map(diagnostic.message)
assert messages == ["Duplicate mapping key `name`"]
}
Types
A typed semantic issue found while resolving YAML.
pub type Diagnostic {
DuplicateMappingKey(
key: String,
duplicate: node.Span,
original: node.Span,
)
DuplicateAnchor(
anchor: String,
duplicate: node.Span,
original: node.Span,
)
UnknownAlias(alias: String, span: node.Span)
InvalidTagDirective(span: node.Span)
InvalidYamlDirective(span: node.Span)
UnsupportedYamlVersion(version: String, span: node.Span)
DuplicateYamlDirective(
duplicate: node.Span,
original: node.Span,
)
UnknownTagHandle(handle: String, span: node.Span)
InvalidTag(tag: String, span: node.Span)
InvalidMergeTarget(found: node.KindName, span: node.Span)
}
Constructors
-
A mapping contains the same scalar key more than once.
The duplicate span points at the repeated key. The original span points at the first matching key.
-
A document contains the same anchor name more than once.
The duplicate span points at the repeated anchor. The original span points at the first matching anchor.
-
UnknownAlias(alias: String, span: node.Span)An alias references an anchor that has not been seen earlier in the document.
-
InvalidTagDirective(span: node.Span)A TAG directive is malformed.
-
InvalidYamlDirective(span: node.Span)A YAML directive is malformed.
-
UnsupportedYamlVersion(version: String, span: node.Span)A YAML directive declares a version this package does not support.
-
A document contains more than one YAML directive.
-
UnknownTagHandle(handle: String, span: node.Span)A node tag uses a handle that has not been declared for the document.
-
InvalidTag(tag: String, span: node.Span)A node tag is malformed.
-
InvalidMergeTarget(found: node.KindName, span: node.Span)A merge key points at a value that is not a mapping.
How serious a diagnostic is.
pub type Severity {
Warning
DiagnosticError
}
Constructors
-
WarningA non-fatal diagnostic.
Resolution can still succeed when a diagnostic has this severity.
-
DiagnosticErrorA fatal diagnostic.
Resolution returns an error when any diagnostic has this severity.
Values
pub fn collect(value: node.Node) -> List(Diagnostic)
Collects non-fatal diagnostics for a parsed YAML node tree.
pub fn errors(diagnostics: List(Diagnostic)) -> List(Diagnostic)
Keeps only fatal diagnostics.
pub fn has_errors(diagnostics: List(Diagnostic)) -> Bool
Returns True when any diagnostic is fatal.
pub fn is_error(diagnostic: Diagnostic) -> Bool
Returns True when a diagnostic is fatal.
pub fn message(diagnostic: Diagnostic) -> String
Renders a human-readable diagnostic message.
pub fn related(diagnostic: Diagnostic) -> List(Related)
Returns related source locations for a diagnostic.
pub fn related_message(related: Related) -> String
Renders a human-readable related-location message.
pub fn severity(diagnostic: Diagnostic) -> Severity
Returns the severity for a diagnostic variant.
pub fn span(diagnostic: Diagnostic) -> node.Span
Returns the primary source span for a diagnostic.
pub fn warnings(
diagnostics: List(Diagnostic),
) -> List(Diagnostic)
Keeps only warning diagnostics.