Bridge Core
Errors
Error types, factories, and validation results.
Import from @workspace/bridge-core/errors.
Base Error
All errors extend BaseError with optional field, path, and typed context:
type ErrorSeverity = "error" | "warning" | "info";Hands Validation Errors
Auction Validation Errors
Play Validation Errors
General Errors
Union Types
type HandsValidationError =
| IncompleteHandsError
| TooManyCardsError
| DuplicateCardError
| InvalidCardRankError;
type AuctionValidationError =
| AuctionNotUsedError
| AuctionRequiredError
| IncompleteAuctionError
| NoContractError
| ContractCalculationError;
type PlayValidationError =
| CardNotOwnedError
| MustFollowSuitError
| TooManyCardsInLineError
| InvalidPlayFormatError;
type GeneralValidationError =
| PayloadValidationError
| ZodValidationError;
type CoreError =
| HandsValidationError
| AuctionValidationError
| PlayValidationError
| GeneralValidationError;Validation Results
Error Factories
import { createHandsError, createAuctionError, createPlayError, createGeneralError } from '@workspace/bridge-core/errors';
const error = createHandsError('INCOMPLETE_HANDS', {
incompletePlayers: ['N', 'S'],
});| Factory | Creates |
|---|---|
createHandsError(type, context) | HandsValidationError |
createAuctionError(type, context) | AuctionValidationError |
createPlayError(type, context) | PlayValidationError |
createGeneralError(type, context) | GeneralValidationError |
PBN Errors
Import from @workspace/bridge-core/errors.
PBN-specific error classes for handling file parsing, encoding, and size issues.
Types
SUPPORTED_ENCODINGS
List of supported file encodings for PBN files:
const SUPPORTED_ENCODINGS = ["UTF-8", "ISO-8859-1", "windows-1252", "UTF-16LE", "UTF-16BE"] as const;Error Classes
| Class | Extends | Description |
|---|---|---|
PBNParseError | Error | Base error for PBN parsing failures. Accepts an optional cause. |
PBNEncodingMismatchError | PBNParseError | Thrown when the declared file encoding does not match the detected encoding. Exposes expectedEncoding and detectedEncoding. |
PBNTooManyDealsError | PBNParseError | Thrown when a PBN file contains more deals than the allowed maximum. Exposes maxDeals and dealCount. |
PNBAggregateError | Error | Aggregate error with typed details: PBNErrorDetails. Accepts an optional cause. |
MaxFileSizeError | Error | Thrown when a file exceeds the maximum size limit. Exposes type, maxSize, and actualSize. |
toPBNError
Converts any PBN error instance into a normalized PBNError object for use in callbacks:
import { toPBNError, MaxFileSizeError } from '@workspace/bridge-core/errors';
const error = new MaxFileSizeError(5, 10);
const pbnError = toPBNError(error);
// { code: "MAX_FILE_SIZE_EXCEEDED", message: "File size exceeds...", details: { maxSize: 5, actualSize: 10 } }The function maps each error class to the appropriate PBNErrorCode. Unknown errors default to "PARSE_ERROR".