PureYAML/Sources/Validation/ValidationError.swift
Mihaela Mihaljevic bf2dc4ece7 refactor(validation): rename framework to match the validation idiom
The validation module already implemented the composable-rule idiom under
its own names (Check/Issue/SubjectContext) and a value-type Validator with
duplicated traversal machinery per layer. Renamed the core types to the
canonical names (Validation/ValidationError/ValidationErrorCollection/
ValidationContext/BuiltinValidation/AnyValidation), converted Validator to
a reference-type class with the two-tier default-rule split, and genericized
it over both Subject and Document via a new Traversable protocol so the
model and tagged layers share one walk engine instead of two copies. Wired
the JSON-representability rule set into the same shape and closed the two
missing pieces (unwrap combinator, JSON coverage/config-pin tests).
2026-07-12 18:10:00 +02:00

27 lines
1.0 KiB
Swift

public extension PureYAML.Validation {
/// Path-aware validation error.
struct ValidationError: Swift.Error, Equatable, Sendable, CustomStringConvertible {
public var severity: Severity
public var reason: String
public var path: Path
public init(
severity: Severity,
reason: String,
path: Path = .root,
) {
self.severity = severity
self.reason = reason
self.path = path
}
/// Strips a trailing period from `reason` and renders the location consistently:
/// `"<reason> at root of document"` at the root, `"<reason> at path: <path>"` elsewhere.
/// `severity` is a separate stored property (see `Result.errors`/`.warnings`), not rendered here.
public var description: String {
let reasonText = reason.hasSuffix(".") ? String(reason.dropLast()) : reason
return path.isRoot ? "\(reasonText) at root of document" : "\(reasonText) at path: \(path.description)"
}
}
}