/** * Centralized type guards for all BrightChain error types. * * This module provides type guards for type-safe error handling across the * BrightChain library. Type guards enable TypeScript to narrow error types * at runtime, allowing for proper type-safe error handling. * * @remarks * - All type guards use `instanceof` checks for O(1) performance * - Type guards return TypeScript type predicates for proper narrowing * - Use these guards in catch blocks for type-safe error handling * * @example * ```typescript * import { * isBrightChainError, * isValidationError, * isChecksumError, * isEnhancedValidationError * } from './typeGuards'; * * try { * // ... operation that might throw * } catch { * if (isChecksumError(error)) { * console.error(`Checksum error (${error.checksumErrorType}): ${error.message}`); * } else if (isEnhancedValidationError(error)) { * console.error(`Validation failed for '${error.field}': ${error.message}`); * } else if (isBrightChainError(error)) { * console.error(`BrightChain error (${error.type}): ${error.message}`); * } else { * throw error; // Re-throw unknown errors * } * } * ``` * * @see Requirements 4.5, 14.4, 14.5, 14.6 * @module */ export { isBrightChainError } from './brightChainError'; export { isChecksumError } from './checksumError'; export { isEnhancedValidationError } from './enhancedValidationError'; export { isFactoryPatternViolationError } from './factoryPatternViolationError'; import { BrightChainError } from './brightChainError'; import { CblError } from './cblError'; import { ChecksumError } from './checksumError'; import { EciesError } from './eciesError'; import { EnhancedValidationError } from './enhancedValidationError'; import { FactoryPatternViolationError } from './factoryPatternViolationError'; import { FecError } from './fecError'; import { TcblError } from './tcblError'; import { TypedError } from './typedError'; import { ValidationError } from './validationError'; /** * Type guard to check if a value is a ValidationError instance. * * @remarks * This checks for the original ValidationError class (not EnhancedValidationError). * For the new error hierarchy, use `isEnhancedValidationError` instead. * * @param error - The value to check * @returns true if the value is a ValidationError instance * * @example * ```typescript * try { * validateInput(data); * } catch { * if (isValidationError(error)) { * console.error(`Validation error (${error.type}): ${error.message}`); * } * } * ``` * * @see Requirement 14.4 */ export declare function isValidationError(error: unknown): error is ValidationError; /** * Type guard to check if a value is an EciesError instance. * * @param error - The value to check * @returns true if the value is an EciesError instance * * @example * ```typescript * try { * eciesService.encrypt(data); * } catch { * if (isEciesError(error)) { * console.error(`ECIES error (${error.type}): ${error.message}`); * } * } * ``` * * @see Requirement 14.4 */ export declare function isEciesError(error: unknown): error is EciesError; /** * Type guard to check if a value is a CblError instance. * * @param error - The value to check * @returns true if the value is a CblError instance * * @example * ```typescript * try { * cblService.createCbl(data); * } catch { * if (isCblError(error)) { * console.error(`CBL error (${error.type}): ${error.message}`); * } * } * ``` * * @see Requirement 14.4 */ export declare function isCblError(error: unknown): error is CblError; /** * Type guard to check if a value is a TcblError instance. * * @param error - The value to check * @returns true if the value is a TcblError instance * * @example * ```typescript * try { * tcblReader.open(); * } catch { * if (isTcblError(error)) { * console.error(`TCBL error (${error.errorType}): ${error.message}`); * } * } * ``` */ export declare function isTcblError(error: unknown): error is TcblError; /** * Type guard to check if a value is a FecError instance. * * @param error - The value to check * @returns true if the value is a FecError instance * * @example * ```typescript * try { * fecService.encode(data); * } catch { * if (isFecError(error)) { * console.error(`FEC error (${error.type}): ${error.message}`); * } * } * ``` * * @see Requirement 14.4 */ export declare function isFecError(error: unknown): error is FecError; /** * Type guard to check if a value is a TypedError instance. * * @remarks * TypedError is the base class for many error types in the codebase. * This guard is useful for catching any typed error regardless of specific type. * * @param error - The value to check * @returns true if the value is a TypedError instance * * @example * ```typescript * try { * someOperation(); * } catch { * if (isTypedError(error)) { * console.error(`Typed error (${error.type}): ${error.message}`); * } * } * ``` * * @see Requirement 14.4 */ export declare function isTypedError(error: unknown): error is TypedError; /** * Type guard to check if a value is any kind of BrightChain-related error. * * @remarks * This is a broad check that returns true for: * - BrightChainError and all its subclasses * - TypedError and all its subclasses * - ValidationError * * Use more specific type guards when you need to handle specific error types. * * @param error - The value to check * @returns true if the value is any BrightChain-related error * * @example * ```typescript * try { * someOperation(); * } catch { * if (isAnyBrightChainError(error)) { * // Handle any BrightChain error * console.error('BrightChain operation failed:', error.message); * } else { * // Handle unexpected errors * throw error; * } * } * ``` * * @see Requirement 14.4 */ export declare function isAnyBrightChainError(error: unknown): error is Error; /** * Utility type for error handling that combines all BrightChain error types. * * @remarks * This type is useful for function signatures that need to handle * any BrightChain error type. */ export type AnyBrightChainError = BrightChainError | ChecksumError | EnhancedValidationError | FactoryPatternViolationError | ValidationError | EciesError | CblError | FecError | TypedError; //# sourceMappingURL=typeGuards.d.ts.map