Error Handling β
The parser supports two modes: lenient (default) and strict.
Lenient mode β
By default, malformed or unrecognized lines do not throw. Instead, they are collected as ScheduleDataSetWarning entries in dataSet.warnings. Unknown record types become records with type === '?' so you can still see them in the flat stream.
import { parseScheduleDataSet } from 'iata-ssim/sds'
const dataSet = parseScheduleDataSet(text)
for (const warning of dataSet.warnings) {
console.warn(`Line ${warning.lineNumber}: ${warning.message}`)
}You can also be notified eagerly via the onWarning callback:
parseScheduleDataSet(text, {
onWarning: w => console.warn(`SSIM: ${w.message} (line ${w.lineNumber})`),
})Strict mode β
Strict mode throws ScheduleDataSetParseError as soon as something unexpected is encountered (unknown record type, malformed line, etc.).
import { parseScheduleDataSet, ScheduleDataSetParseError } from 'iata-ssim/sds'
try {
parseScheduleDataSet(text, { strict: true })
}
catch (err) {
if (err instanceof ScheduleDataSetParseError) {
console.error(`line ${err.lineNumber} (${err.recordType}): ${err.message}`)
}
}ScheduleDataSetParseError exposes:
messageβ human-readable problem descriptionlineNumberβ 1-indexed line in the original inputlineβ the offending source linerecordTypeβ the record-type character that was being processedfieldβ the field name (when the error is field-specific)causeβ the underlying error, if any
Spec validation β
After parsing, parseScheduleDataSet runs the full validator from iata-ssim/sds/validation against the IATA SSIM, March 2012 edition (Β§Β§ 7.5.1β7.5.5). Each violation becomes a ValidationIssue:
interface ValidationIssue {
rule: string // e.g. "Β§ 7.5.2 Time Mode"
message: string
lineNumber: number
recordType: string // "1"β"5"
field?: string // property name on the parsed record
}In lenient mode each issue is added to dataSet.warnings; in strict mode the first issue is thrown as ScheduleDataSetParseError. The error's recordType and field properties point at the offending field.
What gets checked β
Highlights β see validation.ts for the full list:
- Β§ 7.5.1 Header β canonical Title of Contents,
recordSerialNumber === 1. - Β§ 7.5.2 Carrier β Time Mode (
U/L), IATA airline code format, mandatory dates parse as DDMMMYY,validFrom β€ validTo, Schedule Status (P/C), Secure Flight Indicator (S/X/blank, eff. 1 Oct 2012), Electronic Ticketing (EN/ET/blank), Creation Time. - Β§ 7.5.3 Flight Leg β IATA airline + 4-digit flight number, IVI / leg sequence 01β99, service type 1A, period validity, at least one Day of Operation, 3-letter station codes, all four times parse, both UTC offsets, 3-character aircraft type, PRBD OR Aircraft Configuration mandatory (spec note: "Either this field orβ¦"), Secure Flight Indicator.
- Β§ 7.5.4 Segment Data β same identification fields as Flight Leg, single-alpha board/off-point indicators, 3-digit DEI (right-justified, zero-filled), 3-letter board/off points.
- Β§ 7.5.5 Trailer β IATA airline, Continuation/End Code (
C/E),serialNumberCheckReference === recordSerialNumber β 1. - Cross-record β every Type 3/4/5 record's airline designator must match the opening Type 2 Carrier Record.
Stand-alone validator β
If you have a pre-parsed ScheduleDataSet, run validation explicitly:
import { parseScheduleDataSet, validateScheduleDataSet } from 'iata-ssim/sds'
const dataSet = parseScheduleDataSet(text, { strict: false })
const issues = validateScheduleDataSet(dataSet)
for (const issue of issues)
console.warn(`[${issue.rule}] line ${issue.lineNumber}: ${issue.message}`)Per-record validators are also exposed (validateHeaderRecord, validateCarrierRecord, validateFlightLegRecord, validateSegmentDataRecord, validateTrailerRecord) for callers that want to validate records they constructed in memory.
Canonical header constant β
import { EXPECTED_HEADER_TITLE } from 'iata-ssim/sds'
// β "AIRLINE STANDARD SCHEDULE DATA SET"