* DumpDie exception raised by the "dd" (dump and die) function. * This special exception terminates execution while dumping the provided * value as HTML (during HTTP requests) or ANSI (in console/CLI). * * @example * ```ts * // This will dump the user object and terminate * dumper.dd(user) *
| 30 | * ``` |
| 31 | */ |
| 32 | class DumpDieException extends Exception { |
| 33 | static status: number = 500 |
| 34 | static code: string = 'E_DUMP_DIE_EXCEPTION' |
| 35 | |
| 36 | declare fileName: string |
| 37 | declare lineNumber: number |
| 38 | |
| 39 | #dumper: Dumper |
| 40 | #traceSourceIndex: number = 1 |
| 41 | value: unknown |
| 42 | |
| 43 | constructor(value: unknown, dumper: Dumper) { |
| 44 | super('Dump and Die exception') |
| 45 | this.#dumper = dumper |
| 46 | this.value = value |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Returns the source file and line number location for the error |
| 51 | */ |
| 52 | #getErrorSource(): { location: string; line: number } | undefined { |
| 53 | if (this.fileName && this.lineNumber) { |
| 54 | return { |
| 55 | location: this.fileName, |
| 56 | line: this.lineNumber, |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | const source = parse(this)[this.#traceSourceIndex] |
| 61 | if (!source.fileName || !source.lineNumber) { |
| 62 | return |
| 63 | } |
| 64 | |
| 65 | return { |
| 66 | location: source.fileName, |
| 67 | line: source.lineNumber, |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Set the stack trace index for determining the source location. |
| 73 | * This is useful when building nested helpers on top of dump/die functionality. |
| 74 | * |
| 75 | * @param index - Stack trace index (0 = current function, 1 = caller, etc.) |
| 76 | */ |
| 77 | setTraceSourceIndex(index: number) { |
| 78 | this.#traceSourceIndex = index |
| 79 | return this |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Preventing itself from getting reported by the |
| 84 | * AdonisJS exception reporter |
| 85 | */ |
| 86 | report() {} |
| 87 | |
| 88 | /** |
| 89 | * HTTP exception handler that renders the dump as HTML output. |
nothing calls this directly
no outgoing calls
no test coverage detected