Typeset Error.Invalid Input(string)- Module
- std.
typeset - Receiver
- Not applicable
- Minimum arity
- 1
- Maximum arity
- 1
Declaration and parameters
LinkAvailability
Included by default: Pending
Import std.typeset in language mode 5.21.
The current compiler selects std/typeset.tpz for this language mode. Availability in other released editions and inclusion in each installed distribution are Pending.
Source evidence
- compiler/crates/topaz_resolve/src/std/typeset/model.tpz at
b48527d0a174· 7 - compiler/crates/topaz_resolve/src/stdlib.rs at
b48527d0a174· 40
Receiver
Parameter constraints
TypesetError values are returned in Err by the typesetting operations that declare them. InvalidInput carries explanatory text for invalid measured data or boundary structure. InvalidPolicy carries explanatory text for an invalid algorithm configuration.
The string payload describes a cause. Programs distinguish failure categories by matching the variant rather than comparing library message text. Constructing an error value directly preserves its supplied string.
NoBreakOpportunities means a nonempty paragraph has no selectable penalty candidate after validation and filtering. It does not mean that the selected cost model searched unsuccessfully.
NoGreedyPlan means a validated paragraph has selectable candidates but its deterministic greedy baseline cannot reach the final unit. NoPlan means that baseline completed but the selected optimization search found no permitted complete plan.
A successful empty paragraph has two empty plans and zero candidates under the paragraph contract. It is not a missing-opportunity failure.
breakParagraph validates policy configuration before measured items. It then checks candidates, builds the greedy plan, and searches for an optimized plan in that order. The first failing stage determines the returned variant.
The policy stages check geometry, the cost model and grid combination, justification settings, and KnuthPlass settings. Item validation follows source encounter order and checks collected penalty endpoints after the measured units.
classifyBreaks applies its input and break-policy validation rules. The shared error variants do not impose paragraph validation order on break classification.
An Err contains no partial ParagraphResult and does not mutate the supplied input. Previously completed argument effects remain completed. A failure while evaluating an argument keeps its ordinary language diagnostic and prevents the typesetting call.
Related rule: Distinguish invalid data from unavailable plansResult
Effects
Failures
Result and effects
LinkCarries explanatory text. Match the variant to distinguish malformed input from a missing plan.
Why
LinkA named failure category lets callers select a recovery without depending on message wording.
Resolved contracts
LinkRelated entries
LinkDistinguish invalid data from unavailable plans
LinkDistinguish invalid data from unavailable plans
TypesetError values are returned in Err by the typesetting operations that declare them. InvalidInput carries explanatory text for invalid measured data or boundary structure. InvalidPolicy carries explanatory text for an invalid algorithm configuration.
The string payload describes a cause. Programs distinguish failure categories by matching the variant rather than comparing library message text. Constructing an error value directly preserves its supplied string.
NoBreakOpportunities means a nonempty paragraph has no selectable penalty candidate after validation and filtering. It does not mean that the selected cost model searched unsuccessfully.
NoGreedyPlan means a validated paragraph has selectable candidates but its deterministic greedy baseline cannot reach the final unit. NoPlan means that baseline completed but the selected optimization search found no permitted complete plan.
A successful empty paragraph has two empty plans and zero candidates under the paragraph contract. It is not a missing-opportunity failure.
breakParagraph validates policy configuration before measured items. It then checks candidates, builds the greedy plan, and searches for an optimized plan in that order. The first failing stage determines the returned variant.
The policy stages check geometry, the cost model and grid combination, justification settings, and KnuthPlass settings. Item validation follows source encounter order and checks collected penalty endpoints after the measured units.
classifyBreaks applies its input and break-policy validation rules. The shared error variants do not impose paragraph validation order on break classification.
An Err contains no partial ParagraphResult and does not mutate the supplied input. Previously completed argument effects remain completed. A failure while evaluating an argument keeps its ordinary language diagnostic and prevents the typesetting call.
Why
Applications can repair malformed data, choose another policy, or report the absence of a plan when these outcomes stay distinct. Named variants provide that decision without relying on diagnostic wording or silently substituting a different algorithm.
Source evidence
- compiler/crates/topaz_resolve/src/std/typeset/model.tpz at
v5.21.3· 6 - compiler/crates/topaz_resolve/src/std/typeset/admission.tpz at
v5.21.3· 1 - compiler/crates/topaz_resolve/src/std/typeset/measure.tpz at
v5.21.3· 27 - compiler/crates/topaz_resolve/src/std/typeset/greedy.tpz at
v5.21.3· 1 - compiler/crates/topaz_resolve/src/std/typeset/paragraph.tpz at
v5.21.3· 87 - compiler/crates/topaz_resolve/src/std/typeset/breaks.tpz at
v5.21.3· 1 -
topaz.stdlib.contract.typeset-errorsatworking-tree
Preserve explanatory error payloads
Linkimport std.typeset as tsimport std.iolet failures: Array<ts.TypesetError> = [ts.TypesetError.InvalidInput("measured unit"),ts.TypesetError.InvalidPolicy("line target")]for failure in (failures) {match (failure) {case InvalidInput(message) => io.writeLine("input {message}")case InvalidPolicy(message) => io.writeLine("policy {message}")case _ => io.writeLine("unexpected variant")}}
input measured unit policy line target
Expected result
Expected result
Execution completes. Exit code 0.
input measured unitpolicy line target
Source evidence
- compiler/crates/topaz_resolve/src/std/typeset/model.tpz at
v5.21.3· 6 - compiler/crates/topaz_resolve/src/std/typeset/admission.tpz at
v5.21.3· 1 - compiler/crates/topaz_resolve/src/std/typeset/measure.tpz at
v5.21.3· 27 - compiler/crates/topaz_resolve/src/std/typeset/greedy.tpz at
v5.21.3· 1 - compiler/crates/topaz_resolve/src/std/typeset/paragraph.tpz at
v5.21.3· 87 - compiler/crates/topaz_resolve/src/std/typeset/breaks.tpz at
v5.21.3· 1 -
topaz.stdlib.contract.typeset-errorsatworking-tree
Report an invalid paragraph policy before an invalid unit index
Linkimport std.typeset as tsimport std.iolet items: Array<ts.Item> = [ts.Item.BoxItem(ts.Box { unitIndex: 1, text: "a", width: 1pt, trackingAfter: 0pt }),ts.Item.PenaltyItem(ts.Penalty { unitEnd: 1, width: 0pt, rule: ts.BreakRule.Forced(), kind: ts.BreakKind.ForcedEnd(), flagged: false })]let input = ts.Paragraph {grid: ts.DistanceGrid.MilliPoint(),items: items,geometry: ts.LineGeometry { bodyTarget: 0pt, firstTarget: 0pt, dropCapSpan: 0, dropCapInset: 0pt },justification: ts.JustificationPolicy {mode: ts.JustificationMode.Unjustified(), minGapCount: 0,minLineWidthRatioM: 0, minFinalLineWidthRatioM: None(),maxAdjustment: 0pt, maxGapAdjustment: 0pt, maxGapRatioR: 0,latinSpacing: None(), cjkStretchRatio: 0.0},costModel: ts.CostModel.FixedPoint(),knuthPlass: ts.KnuthPlassPolicy { toleranceR: 100000000, linePenalty: 10, fitnessDemerit: 0, flaggedDemerit: 0, finalFlaggedDemerit: 0 }}match (ts.breakParagraph(input)) {case Err(InvalidPolicy(_)) => io.writeLine("InvalidPolicy")case _ => io.writeLine("unexpected result")}
InvalidPolicy
Expected result
Expected result
Execution completes. Exit code 0.
InvalidPolicy
Source evidence
- compiler/crates/topaz_resolve/src/std/typeset/model.tpz at
v5.21.3· 6 - compiler/crates/topaz_resolve/src/std/typeset/admission.tpz at
v5.21.3· 1 - compiler/crates/topaz_resolve/src/std/typeset/measure.tpz at
v5.21.3· 27 - compiler/crates/topaz_resolve/src/std/typeset/greedy.tpz at
v5.21.3· 1 - compiler/crates/topaz_resolve/src/std/typeset/paragraph.tpz at
v5.21.3· 87 - compiler/crates/topaz_resolve/src/std/typeset/breaks.tpz at
v5.21.3· 1 -
topaz.stdlib.contract.typeset-errorsatworking-tree