Skip to main content

Troubleshooting

Every refusal in @cosyte/dates is named. This page lists them and what to do about each.

Errors​

errorthrown whenwhat to do
DatePartsErrora conversion or assertValidParts() is given a value that fails validationread error.issues: the same array validateParts() returns for that value
PrecisionErrorthe value lacks a component the conversion needsbranch on precisionOf() first; error.precision is the precision it has
MissingZoneErroran instant is asked for, the value has no offset, and no zone was passedpass { timeZone } or { offsetMinutes } for the zone the sender meant
AmbiguousLocalTimeErrorthe local time is skipped or repeated by a daylight-saving transitionpass the offset you mean as { offsetMinutes }; the message names the candidates
RangeErrorthe timeZone is not an identifier Temporal knowsuse an IANA identifier such as America/New_York, or a numeric offset
TypeErrorboth timeZone and offsetMinutes are passedpass one of them

The four named error classes are exported, so instanceof works:

import { toInstant, MissingZoneError } from '@cosyte/dates';

try {
toInstant({ year: 1988, month: 5, day: 7, hour: 13, minute: 45 });
} catch (error) {
if (error instanceof MissingZoneError) {
// ask which zone the sender was in; never assume one
}
}

Issue codes​

validateParts() returns one issue per fault, each with a component, a code and a message:

codemeaning
not-a-parts-objectthe argument is not an object at all
missing-componenta more significant component is absent while a less significant one is set
unreadablereading the component threw, so its value could not be seen
not-a-numberthe component is present but is not a number
not-finitethe component is NaN or infinite
not-an-integerthe component must be a whole number and is not
out-of-rangethe component is outside the range its row in the contract gives it
year-not-four-digitsthe year is not four digits; no century window is ever applied
finer-than-nanosecondfraction carries detail below one nanosecond; it is not rounded
offset-without-time-of-dayoffsetMinutes is set on a value that states no time of day
no-such-calendar-dateeach component is in range, but together they name no real date

Logging​

A validation message quotes the one component at fault and its value (month must be an integer in 1-12 ...; received the number 13). It never assembles the full date into the message. A date of birth is PHI, so decide whether to log even one component before you log a message.

The package itself writes nothing: no logging, no telemetry, no files and no network, on any code path.