errors
errors is a module in @cipherstash/stack. TypeScript API reference with its signature, parameters, and usage.
errors
Interfaces
EncryptionError
Defined in: errors/index.ts:37
Base error interface returned by all encryption operations.
Every operation that can fail returns Result<T, EncryptionError>.
Use the type field to narrow to a specific error kind, or use
StackError for an exhaustive discriminated union.
Example
const result = await client.encrypt(value, opts)
if (result.failure) {
switch (result.failure.type) {
case EncryptionErrorTypes.EncryptionError:
console.error('Encryption failed:', result.failure.message)
break
case EncryptionErrorTypes.LockContextError:
console.error('Lock context issue:', result.failure.message)
break
}
}Properties
type
type:
| "ClientInitError"
| "EncryptionError"
| "DecryptionError"
| "LockContextError"
| "CtsTokenError";Defined in: errors/index.ts:38
message
message: string;Defined in: errors/index.ts:39
code?
optional code: ProtectErrorCode;Defined in: errors/index.ts:40
ClientInitError
Defined in: errors/index.ts:47
Properties
type
type: "ClientInitError";Defined in: errors/index.ts:48
message
message: string;Defined in: errors/index.ts:49
EncryptionOperationError
Defined in: errors/index.ts:52
Properties
type
type: "EncryptionError";Defined in: errors/index.ts:53
message
message: string;Defined in: errors/index.ts:54
code?
optional code: ProtectErrorCode;Defined in: errors/index.ts:55
DecryptionOperationError
Defined in: errors/index.ts:58
Properties
type
type: "DecryptionError";Defined in: errors/index.ts:59
message
message: string;Defined in: errors/index.ts:60
code?
optional code: ProtectErrorCode;Defined in: errors/index.ts:61
LockContextError
Defined in: errors/index.ts:64
Properties
type
type: "LockContextError";Defined in: errors/index.ts:65
message
message: string;Defined in: errors/index.ts:66
CtsTokenError
Defined in: errors/index.ts:69
Properties
type
type: "CtsTokenError";Defined in: errors/index.ts:70
message
message: string;Defined in: errors/index.ts:71
Type Aliases
StackError
type StackError =
| ClientInitError
| EncryptionOperationError
| DecryptionOperationError
| LockContextError
| CtsTokenError;Defined in: errors/index.ts:102
Discriminated union of all specific error types.
Use StackError when you need exhaustive error handling via switch on the type field.
Example
function handleError(error: StackError) {
switch (error.type) {
case 'ClientInitError':
// re-initialize client
break
case 'EncryptionError':
case 'DecryptionError':
// log and retry
break
case 'LockContextError':
// re-authenticate
break
case 'CtsTokenError':
// refresh token
break
default:
error satisfies never
}
}Variables
EncryptionErrorTypes
const EncryptionErrorTypes: {
ClientInitError: "ClientInitError";
EncryptionError: "EncryptionError";
DecryptionError: "DecryptionError";
LockContextError: "LockContextError";
CtsTokenError: "CtsTokenError";
};Defined in: errors/index.ts:7
Type Declaration
ClientInitError
readonly ClientInitError: "ClientInitError" = 'ClientInitError';EncryptionError
readonly EncryptionError: "EncryptionError" = 'EncryptionError';DecryptionError
readonly DecryptionError: "DecryptionError" = 'DecryptionError';LockContextError
readonly LockContextError: "LockContextError" = 'LockContextError';CtsTokenError
readonly CtsTokenError: "CtsTokenError" = 'CtsTokenError';Functions
getErrorMessage()
function getErrorMessage(error): string;Defined in: errors/index.ts:117
Safely extract an error message from an unknown thrown value.
Unlike (error as Error).message, this handles non-Error values gracefully.
Parameters
error
unknown
Returns
string