Skip to main content
Version: v0.0.4

Class: Hl7ParseError

Thrown by parseHL7 when the input violates one of the 4 unrecoverable Tier-3 structural rules (missing MSH, truncated MSH, invalid encoding characters, or empty input). Carries positional context plus a short snippet of the offending input so consumers can log actionable errors.

Remarks

snippet may contain PHI when parsing real clinical messages, and the library does not redact it: redact at the call site if required by your compliance posture. It is the only field carrying input verbatim and unfiltered (capped at 40 characters plus an ellipsis, but not shape-checked in any way), so it is the one to redact first.

message is bounded but not absolutely content-free, and the difference is worth stating because message is what a logger prints by default and what stack embeds. A token lifted from the input is echoed only when it matches the form the spec defines for it: a three-character segment identifier, an MSH-9 type, an MSH-12 version, or a charset label the closed Table 0211 actually contains. Anything else becomes <withheld>. So a message cannot carry a field's value, but it can carry a residue of up to three characters when a malformed line happens to look like a segment identifier. The other shapes are narrower in practice than their patterns allow, because the library only ever feeds them registry-matched values, but the patterns themselves admit more (a message type up to 26 characters, a version up to 14), which matters if you construct warnings yourself.

Under { strict: true } an escalated Tier-2 warning is thrown as this error, carrying the warning's own bounded message and a snippet of the first 40 characters of the input. That snippet is the head of the message rather than the deviation's own segment, so it is usually the MSH header; it is deliberately not re-pointed at the offending segment, since doing so would move more clinical content into the unredacted field.

Example

import { parseHL7, Hl7ParseError } from "@cosyte/hl7";
try {
parseHL7("");
} catch (err) {
if (err instanceof Hl7ParseError && err.code === "EMPTY_INPUT") {
// handle empty input: err.position, err.snippet available
}
}

Extends

  • Error

Constructors

Constructor

new Hl7ParseError(code, message, position, snippet): Hl7ParseError

Internal

Construct a new Hl7ParseError. All four fields are required so every thrower populates full positional context per the TOL-02 requirement.

Parameters

code

FatalCode

message

string

position

Hl7Position

snippet

string

Returns

Hl7ParseError

Overrides

Error.constructor

Properties

code

readonly code: FatalCode


position

readonly position: Hl7Position


snippet

readonly snippet: string