Skip to content

Error Codes

SDF defines a set of standard error codes used consistently across all implementations — sdf-kit, sdf-cli, sdf-server, and the Python SDK. All errors produced by an SDF operation MUST use one of these codes.

Do not invent new error codes. If a situation is not covered by the existing codes, open a GitHub issue on the etapsky/sdf repository to propose a new code with spec section coverage.


Error Code Reference

CodeTriggerTypical Cause
SDF_ERROR_NOT_ZIPFile is not a valid ZIP archiveWrong file extension, corrupted download, truncated upload
SDF_ERROR_INVALID_METAmeta.json is missing or fails validationMissing required fields, wrong value types, non-UUID document_id, invalid date format
SDF_ERROR_MISSING_FILEA required archive entry is absentIncomplete producer implementation, partially written archive
SDF_ERROR_SCHEMA_MISMATCHdata.json fails validation against schema.jsonBusiness data does not match the declared schema, producer bug, schema drift
SDF_ERROR_INVALID_SCHEMAschema.json is not valid JSON Schema Draft 2020-12Schema syntax error, external $ref URI, invalid $schema value
SDF_ERROR_UNSUPPORTED_VERSIONsdf_version value is higher than the consumer supportsConsumer is on an older spec version than the producer
SDF_ERROR_INVALID_SIGNATURESignature verification failsKey mismatch, tampered data or visual layer, wrong key_id
SDF_ERROR_INVALID_ARCHIVEPath traversal or structural violationMalformed ZIP, .. in entry path, unrecognized root-level entry, symlink entries
SDF_ERROR_ARCHIVE_TOO_LARGEArchive exceeds size limitsOversized embedded PDF, ZIP bomb attempt, uncompressed total > 200 MB

TypeScript Error Handling

All sdf-kit functions throw SDFError instances. SDFError extends the native Error class and adds a code property typed to the union of error code constants.

SDFError class
// packages/sdf-kit/src/core/errors.ts
export type SDFErrorCode =
| 'SDF_ERROR_NOT_ZIP'
| 'SDF_ERROR_INVALID_META'
| 'SDF_ERROR_MISSING_FILE'
| 'SDF_ERROR_SCHEMA_MISMATCH'
| 'SDF_ERROR_INVALID_SCHEMA'
| 'SDF_ERROR_UNSUPPORTED_VERSION'
| 'SDF_ERROR_INVALID_SIGNATURE'
| 'SDF_ERROR_INVALID_ARCHIVE'
| 'SDF_ERROR_ARCHIVE_TOO_LARGE';
export class SDFError extends Error {
readonly code: SDFErrorCode;
constructor(code: SDFErrorCode, message: string) {
super(message);
this.name = 'SDFError';
this.code = code;
}
}
Handling SDF errors
import { parseSDF, SDFError } from '@etapsky/sdf-kit';
import { readFileSync } from 'fs';
const buffer = readFileSync('./invoice.sdf');
try {
const sdf = await parseSDF(buffer);
console.log('Document type:', sdf.meta.document_type);
console.log('Issuer:', sdf.meta.issuer);
} catch (err) {
if (err instanceof SDFError) {
switch (err.code) {
case 'SDF_ERROR_NOT_ZIP':
console.error('Not a valid SDF file (not a ZIP archive)');
break;
case 'SDF_ERROR_MISSING_FILE':
console.error('Incomplete SDF archive:', err.message);
break;
case 'SDF_ERROR_SCHEMA_MISMATCH':
console.error('Data validation failed:', err.message);
break;
case 'SDF_ERROR_ARCHIVE_TOO_LARGE':
console.error('Archive exceeds size limits — possible ZIP bomb');
break;
case 'SDF_ERROR_INVALID_ARCHIVE':
console.error('Archive structure violation:', err.message);
break;
default:
console.error(`SDF error [${err.code}]:`, err.message);
}
} else {
// Not an SDF error — unexpected failure
throw err;
}
}

Python Error Handling

The Python SDK (etapsky-sdf) raises SDFError with the same error codes:

Handling SDF errors in Python
from etapsky_sdf import parse_sdf, SDFError
with open("invoice.sdf", "rb") as f:
buffer = f.read()
try:
sdf = parse_sdf(buffer)
print(f"Document type: {sdf.meta['document_type']}")
print(f"Issuer: {sdf.meta['issuer']}")
except SDFError as e:
if e.code == "SDF_ERROR_NOT_ZIP":
print("Not a valid SDF file (not a ZIP archive)")
elif e.code == "SDF_ERROR_MISSING_FILE":
print(f"Incomplete SDF archive: {e}")
elif e.code == "SDF_ERROR_SCHEMA_MISMATCH":
print(f"Data validation failed: {e}")
elif e.code == "SDF_ERROR_ARCHIVE_TOO_LARGE":
print("Archive exceeds size limits — possible ZIP bomb")
elif e.code == "SDF_ERROR_INVALID_ARCHIVE":
print(f"Archive structure violation: {e}")
else:
print(f"SDF error [{e.code}]: {e}")

Error Code Usage by Pipeline Step

Each validation pipeline step produces a specific subset of error codes:

Pipeline StepPossible Error Codes
Container validationSDF_ERROR_NOT_ZIP, SDF_ERROR_INVALID_ARCHIVE, SDF_ERROR_ARCHIVE_TOO_LARGE, SDF_ERROR_MISSING_FILE
Meta validationSDF_ERROR_INVALID_META, SDF_ERROR_UNSUPPORTED_VERSION
Schema validationSDF_ERROR_INVALID_SCHEMA
Data validationSDF_ERROR_SCHEMA_MISMATCH
Signature verificationSDF_ERROR_INVALID_SIGNATURE

This mapping enables consumers to provide precise error diagnostics and log structured errors with the pipeline step that failed.


HTTP Mapping

When the SDF server returns validation errors over HTTP, error codes map to HTTP status codes as follows:

SDF Error CodeHTTP StatusNotes
SDF_ERROR_NOT_ZIP422 Unprocessable EntityClient sent a non-ZIP file
SDF_ERROR_INVALID_META422 Unprocessable Entitymeta.json validation failure
SDF_ERROR_MISSING_FILE422 Unprocessable EntityRequired entry absent
SDF_ERROR_SCHEMA_MISMATCH422 Unprocessable Entitydata.json validation failure
SDF_ERROR_INVALID_SCHEMA422 Unprocessable Entityschema.json is malformed
SDF_ERROR_UNSUPPORTED_VERSION422 Unprocessable EntityConsumer cannot process this version
SDF_ERROR_INVALID_SIGNATURE422 Unprocessable EntitySignature verification failed
SDF_ERROR_INVALID_ARCHIVE400 Bad RequestStructural violation or security issue
SDF_ERROR_ARCHIVE_TOO_LARGE413 Content Too LargeArchive exceeds size limits

CLI Exit Codes

sdf-cli returns the following exit codes when errors are encountered:

Exit CodeMeaningError Codes
0Validation succeeded
1SDF validation errorAny SDF_ERROR_*
2Usage errorWrong arguments or missing input file
3Unexpected internal errorNon-SDF exception