UNPKG

@aptos-labs/ts-sdk

Version:
33 lines (31 loc) 1 kB
/** * This error is used to explain why parsing failed. */ declare class ParsingError<T> extends Error { /** * This provides a programmatic way to access why parsing failed. Downstream devs * might want to use this to build their own error messages if the default error * messages are not suitable for their use case. This should be an enum. */ invalidReason: T; constructor(message: string, invalidReason: T); } /** * Whereas ParsingError is thrown when parsing fails, e.g. in a fromString function, * this type is returned from "defensive" functions like isValid. */ type ParsingResult<T> = { /** * True if valid, false otherwise. */ valid: boolean; /** * If valid is false, this will be a code explaining why parsing failed. */ invalidReason?: T; /** * If valid is false, this will be a string explaining why parsing failed. */ invalidReasonMessage?: string; }; export { ParsingError, type ParsingResult };