setBaseErrorOptions()function

setBaseErrorOptions(defaultCaller: AnyCaller, error: BaseError, options: BaseErrorOptions): void
ParamType
defaultCallerAnyCaller
Function to attribute the stack to when options.caller is not supplied. required
errorBaseError
The BaseError instance to mutate with contextual data and a trimmed stack. required
optionsBaseErrorOptions
Options to apply — cause and caller are consumed, all other keys are copied onto error. required
    .callerAnyCaller
Modify the stack to trim off lines after a certain calling function.
Return
void
Nothing — error is mutated in place.

Apply BaseErrorOptions to an error instance by copying contextual fields onto it and trimming its stack.

  • Copies every option except cause and caller onto the error as a named property.
  • Uses Error.captureStackTrace() with the resolved caller so the stack points at the user's call site, not the error plumbing.

Examples

const error = new ValueError("Wrong");
	setBaseErrorOptions(ValueError, error, { received: 123, caller: myFunction });