Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
import * as makeError from "make-error";
import { inspect } from "util";

/**
* See https://nodejs.org/docs/latest/api/util.html#custom-inspection-functions-on-objects
*/
const customInspectSymbol = Symbol.for('nodejs.util.inspect.custom');

/**
* See https://docs.deno.com/api/node/util/~/InspectOptions
*/
type InspectOptions = {
customInspect: boolean;
}

type InspectFunction = (value: any, options?: InspectOptions) => string;

/**
* @internal
Expand All @@ -20,15 +33,15 @@ export class BaseError extends makeError.BaseError {
});
}

[inspect.custom || /* istanbul ignore next */ "inspect"]() {
return fullStack(this);
[customInspectSymbol](depth: number, inspectOptions: InspectOptions, inspect: InspectFunction): string {
return fullStack(this, inspect);
}
}

/**
* Capture the full stack trace of any error instance.
*/
export function fullStack(error: Error | BaseError) {
export function fullStack(error: Error | BaseError, inspect: InspectFunction): string {
const chain: Error[] = [];
let cause: Error | undefined = error;

Expand Down