tryError Documentation
Function: createScope()
Function
```ts function createScope(config): { config: { captureStackTrace?: boolean; defaultErrorType?: string; developmentMode?: boolean; environmentHandlers?: { client?: (error) => TryError; edge?: (error) => TryError; server?: (error) => TryError; }; includeSource?: boolean; minimalErrors?: boolean; onError?: (error) => TryError; performance?: PerformanceConfig; runtimeDetection?: boolean; serializer?: (error) => Record<string, unknown>; skipContext?: boolean; skipTimestamp?: boolean; sourceLocation?: { defaultStackOffset?: number; format?: "full" | "file:line:column" | "file:line" | "file"; formatter?: (file, line, column) => string; includeFullPath?: boolean; }; stackTraceLimit?: number; }; createError: (options) => Promise<TryError<string>>; }; ``` Defined in: [config.ts:820](https://github.com/oconnorjohnson/try-error/blob/e3ae0308069a4fba073f4543d527ad76373db795/src/config.ts#L820) Create a scoped configuration that doesn't affect global state Useful for testing or isolated components
tryError API Documentation v0.0.1-alpha.1
tryError API Documentation / createScope
Function: createScope()
function createScope(config): {
config: {
captureStackTrace?: boolean;
defaultErrorType?: string;
developmentMode?: boolean;
environmentHandlers?: {
client?: (error) => TryError;
edge?: (error) => TryError;
server?: (error) => TryError;
};
includeSource?: boolean;
minimalErrors?: boolean;
onError?: (error) => TryError;
performance?: PerformanceConfig;
runtimeDetection?: boolean;
serializer?: (error) => Record<string, unknown>;
skipContext?: boolean;
skipTimestamp?: boolean;
sourceLocation?: {
defaultStackOffset?: number;
format?: "full" | "file:line:column" | "file:line" | "file";
formatter?: (file, line, column) => string;
includeFullPath?: boolean;
};
stackTraceLimit?: number;
};
createError: (options) => Promise<TryError<string>>;
};
Defined in: config.ts:820
Create a scoped configuration that doesn't affect global state Useful for testing or isolated components
Parameters
config
Scoped configuration
Returns
{
config: {
captureStackTrace?: boolean;
defaultErrorType?: string;
developmentMode?: boolean;
environmentHandlers?: {
client?: (error) => TryError;
edge?: (error) => TryError;
server?: (error) => TryError;
};
includeSource?: boolean;
minimalErrors?: boolean;
onError?: (error) => TryError;
performance?: PerformanceConfig;
runtimeDetection?: boolean;
serializer?: (error) => Record<string, unknown>;
skipContext?: boolean;
skipTimestamp?: boolean;
sourceLocation?: {
defaultStackOffset?: number;
format?: "full" | "file:line:column" | "file:line" | "file";
formatter?: (file, line, column) => string;
includeFullPath?: boolean;
};
stackTraceLimit?: number;
};
createError: (options) => Promise<TryError<string>>;
}
Functions that use the scoped config
config
config: {
captureStackTrace?: boolean;
defaultErrorType?: string;
developmentMode?: boolean;
environmentHandlers?: {
client?: (error) => TryError;
edge?: (error) => TryError;
server?: (error) => TryError;
};
includeSource?: boolean;
minimalErrors?: boolean;
onError?: (error) => TryError;
performance?: PerformanceConfig;
runtimeDetection?: boolean;
serializer?: (error) => Record<string, unknown>;
skipContext?: boolean;
skipTimestamp?: boolean;
sourceLocation?: {
defaultStackOffset?: number;
format?: "full" | "file:line:column" | "file:line" | "file";
formatter?: (file, line, column) => string;
includeFullPath?: boolean;
};
stackTraceLimit?: number;
} = scopedConfig;
config.captureStackTrace?
optional captureStackTrace: boolean;
Whether to capture stack traces (expensive operation)
Default
true in development, false in production;
config.defaultErrorType?
optional defaultErrorType: string;
Default error type for untyped errors
Default
"Error";
config.developmentMode?
optional developmentMode: boolean;
Enable development mode features (verbose logging, etc.)
Default
false;
config.environmentHandlers?
optional environmentHandlers: {
client?: (error) => TryError;
edge?: (error) => TryError;
server?: (error) => TryError;
};
Environment-specific error handlers (used with runtimeDetection)
config.environmentHandlers.client()?
optional client: (error) => TryError;
Parameters
error
Returns
config.environmentHandlers.edge()?
optional edge: (error) => TryError;
Parameters
error
Returns
config.environmentHandlers.server()?
optional server: (error) => TryError;
Parameters
error
Returns
config.includeSource?
optional includeSource: boolean;
Include source location in errors
Default
true;
config.minimalErrors?
optional minimalErrors: boolean;
Enable minimal error mode for ultra-lightweight errors
Default
false;
config.onError()?
optional onError: (error) => TryError;
Global error transformation hook
Parameters
error
Returns
config.performance?
optional performance: PerformanceConfig;
Performance optimization configuration
config.runtimeDetection?
optional runtimeDetection: boolean;
Runtime environment detection for isomorphic apps (Next.js, Nuxt, etc.) When enabled, environment-specific handlers are called based on runtime detection
Default
false;
config.serializer()?
optional serializer: (error) => Record<string, unknown>;
Custom error serialization function
Parameters
error
Returns
Record
<string
, unknown
>
config.skipContext?
optional skipContext: boolean;
Skip context processing
Default
false;
config.skipTimestamp?
optional skipTimestamp: boolean;
Skip timestamp generation (Date.now() calls)
Default
false;
config.sourceLocation?
optional sourceLocation: {
defaultStackOffset?: number;
format?: "full" | "file:line:column" | "file:line" | "file";
formatter?: (file, line, column) => string;
includeFullPath?: boolean;
};
Source location configuration
config.sourceLocation.defaultStackOffset?
optional defaultStackOffset: number;
Default stack offset for source detection Useful when wrapping error creation
Default
3;
config.sourceLocation.format?
optional format: "full" | "file:line:column" | "file:line" | "file";
Format for source location string
Default
"file:line:column";
config.sourceLocation.formatter()?
optional formatter: (file, line, column) => string;
Custom source location formatter
Parameters
file
string
line
string
column
string
Returns
string
config.sourceLocation.includeFullPath?
optional includeFullPath: boolean;
Include full file path or just filename
Default
false (just filename)
config.stackTraceLimit?
optional stackTraceLimit: number;
Maximum stack trace depth to capture
Default
10;
createError()
createError: (options) => Promise<TryError<string>>;
Parameters
options
Omit
<CreateErrorOptions
<string
>, "type"
> & {
type?
: string
;
}
Returns
Promise
<TryError
<string
>>
Example
const { createError } = createScope({
captureStackTrace: false,
defaultErrorType: "CustomError",
});
const error = createError({ message: "Test error" });