Yams validates and reads; writes are surgical line-span edits over retained raw text, so untouched bytes — unknown keys, comments, odd formatting, bodies — round-trip identically by construction. Strict schema/order readers distinguish valid/missing/malformed for the loader's fail-fast; lenient fields preserve malformed values verbatim; modified-by is schema-owned. Adds the Yams package and the fixture folder-reference wiring. 44 tests (105 cases). Claude-Session: https://claude.ai/code/session_018BjQRYBR6jQja3jCRi5S3A
25 lines
1.0 KiB
Swift
25 lines
1.0 KiB
Swift
import Foundation
|
|
|
|
/// Structural failures parsing an `index.md`. Everything here is fail-fast material
|
|
/// (01-storage-format.md § Malformed input); lenient field problems never surface as errors.
|
|
public enum FrontmatterError: Error, Equatable, Sendable, CustomStringConvertible {
|
|
case missingOpeningDelimiter
|
|
case missingClosingDelimiter
|
|
/// `line` is 1-based within the whole file, not within the YAML block.
|
|
case unparseableYAML(message: String, line: Int?)
|
|
case frontmatterNotAMapping
|
|
|
|
public var description: String {
|
|
switch self {
|
|
case .missingOpeningDelimiter:
|
|
"File does not start with a '---' frontmatter delimiter"
|
|
case .missingClosingDelimiter:
|
|
"Frontmatter is never closed by a '---' delimiter"
|
|
case let .unparseableYAML(message, line):
|
|
line.map { "Unparseable YAML at line \($0): \(message)" } ?? "Unparseable YAML: \(message)"
|
|
case .frontmatterNotAMapping:
|
|
"Frontmatter is not a YAML mapping"
|
|
}
|
|
}
|
|
}
|