formats: Xml is a Format<XmlError>, with a failing twin for encodeAll and encoded (step 3c of #78) #805
Labels
No labels
loop
queue/failed
queue/queued
ready
status/parked
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
torbscript/language#805
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Context
Step 3c of #78.
Xmlhasdecode,encodeandtree(steps 3a, 3b, 3b-fix), but is not yet aFormat<XmlError>, so a function written for any format (fn load<Chosen: Format<Problem>, Problem>(...)) cannot take it, and neither can the streaming entry points the S3 and WebDAV drivers (#20, #67) will want. The blocker is in the trait:Format.encodeAllandFormat.encodedare declared as never failing (STREAMS.md section 10),Xml.encodecan fail on data (a root that is no record,Noneinside a list, a map key that is no XML name, a character XML 1.0 forbids), and PANICS.md rule 1 forbids a panic for a failure that depends on the data.Decision (by the loop)
Additive failing twin, not a changed signature.
encodeAllis published andJsonimplements it; changing its result type would break that contract. So:Format<Failure>gainsstatic fn tryEncodeAll<Value: Encode>(value: Value): Result<Bytes, Failure>andstatic fn tryEncoded<Item: Encode>(): Stage<Item, Result<Bytes, Failure>>, both with a default body that wraps the existing member (Ok(encodeAll(value)), and the stage mappingencodedintoOk), soJsonand any other implementer keep compiling unchanged. If a trait cannot carry a static default yet,Jsongets the two explicit one-line implementations instead; the trait stays additive for callers either way.XmlimplementsFormat<XmlError>:tryEncodeAll/tryEncodedare the faithful pair (theXmlErrorofXml().encodeis the failure);encodeAll/encodedare the lossy pair, documented as such: a value XML cannot say gives empty bytes (no partial document), and code that must see the failure uses thetrypair.decodeAllisXml().decodeover UTF-8 text with the sameinvalidTexthandlingJsonhas.itemsreads one document, since XML has exactly one root: it holds the bytes of the stream until its end and yields at most oneResult<Item, XmlError>(memory is the document; documented as the difference fromJson's framer, no framer for concatenated documents).compiler/CONTRIBUTING.mdnaming rules say otherwise; if so, follow them and record it in the PR.Design record point
STREAMS.md section 10 (trait text and the paragraph on
Failure), ENCODING.md section 14 point 5 and section 16 point 18 (the "step 3c" sentence),std/encodingdoc comment ofFormat,docs/standard-library/xml.md. Touches the seed? No: the compiler does not importstd/xmlorFormat, and no std name is looked up by string. If the implementation finds otherwise, it carries the two-commit seed rule itself.Acceptance criteria
Formathas the twotrymembers with defaults;std/jsoncompiles and its existingFormattests pass unchanged; a test pins thatJson.tryEncodeAll(v)equalsOk(Json.encodeAll(v)).Xmlis aFormat<XmlError>; a generic functionfn roundTrip<F: Format<P>, P>(...)overXmlcompiles and a record round-trips throughtryEncodeAllanddecodeAll.Xml.encoderejects (root that is no record) answersErr(XmlError)fromtryEncodeAllandtryEncoded, gives empty bytes fromencodeAll/encoded, and never panics (test for each).Xml.items<T>()over a stream split at arbitrary byte borders yields the same single item asdecodeAll, and a truncated document yields anErr.docs/standard-library/xml.mdstate the twin and the lossy pair; theFormatdoc comment is updated.CLAUDE.mdpass (fmt, check, tests, docs gate,.trblint).Plan
One PR, two Conventional Commits: (1)
feat(encoding): Format gets the failing twins tryEncodeAll and tryEncoded(trait, defaults, Json test, STREAMS.md); (2)feat(xml): Xml is a Format<XmlError>(impl, tests, docs, ENCODING.md status line).Part of #78. Next in the epic after this: step 4, the mapping DSL.
std/xml#78std/xml#78std/xml#78[loop:torbscript] claim implement by session:loop-torbscript-805-impl until 2026-11-15T06:55Z
std/xml#78[loop:torbscript] release implement: PR #806 open, CI pending (runner queue was backed up for ~2.5h; commit messages, pdisc and change-scan green, gates/tier A still running), worker usage about 400k tokens (sonnet). next: waiting (merge gate)
[loop:torbscript] claim implement by session:loop-torbscript-805-fix until 2026-11-15T10:30Z (fix of PR #806: commit messages check red)
[loop:torbscript] release implement by session:loop-torbscript-805-fix: PR #806 open, head
2f9fc08c(style(xml) subject reworded to chore(xml), tree unchanged), CI pending. next: review (merge gate)std/xml#78