-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
refactor(onerror): inline error page template as string constant #5868
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0e3da0f
20b7b70
de393de
5277c66
1e98ce1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,18 @@ import stackTrace, { type StackFrame } from 'stack-trace'; | |
| import { detectErrorMessage } from './utils.ts'; | ||
|
|
||
| const startingSlashRegex = /\\|\//; | ||
| const defaultConfigIgnoreList: (string | RegExp)[] = [ | ||
| 'pass', | ||
| 'pwd', | ||
| 'passd', | ||
| 'passwd', | ||
| 'password', | ||
| 'keys', | ||
| 'masterKey', | ||
| 'accessKey', | ||
| /secret/i, | ||
| ]; | ||
| const redactedValue = '<Redacted>'; | ||
|
|
||
| export interface FrameSource { | ||
| pre: string[]; | ||
|
|
@@ -302,13 +314,69 @@ export class ErrorView { | |
| baseDir: string; | ||
| config: string; | ||
| } { | ||
| let config = this.app.config; | ||
| if ('dumpConfigToObject' in this.app && typeof this.app.dumpConfigToObject === 'function') { | ||
| config = this.app.dumpConfigToObject().config.config; | ||
| } | ||
| const config = this.serializeConfig(); | ||
| return { | ||
| baseDir: this.app.config.baseDir as string, | ||
| config: util.inspect(config) satisfies string as string, | ||
| }; | ||
| } | ||
|
|
||
| serializeConfig(): unknown { | ||
| if ('dumpConfigToObject' in this.app && typeof this.app.dumpConfigToObject === 'function') { | ||
| return this.app.dumpConfigToObject().config.config; | ||
| } | ||
|
|
||
| return this.redactConfig(this.app.config, this.getConfigIgnoreList()); | ||
| } | ||
|
killagu marked this conversation as resolved.
|
||
|
|
||
| getConfigIgnoreList(): (string | RegExp)[] { | ||
| try { | ||
| return Array.from(this.app.config.dump.ignore); | ||
| } catch { | ||
| return defaultConfigIgnoreList; | ||
| } | ||
| } | ||
|
|
||
| redactConfig( | ||
| value: unknown, | ||
| ignoreList: (string | RegExp)[], | ||
| ancestors: WeakSet<object> = new WeakSet<object>(), | ||
| ): unknown { | ||
| if (!value || typeof value !== 'object') { | ||
| return value; | ||
| } | ||
|
|
||
| if (value instanceof Date || value instanceof RegExp || value instanceof URL) { | ||
| return value.toString(); | ||
| } | ||
|
|
||
| if (Buffer.isBuffer(value)) { | ||
|
Comment on lines
+349
to
+353
|
||
| return value; | ||
| } | ||
|
|
||
| if (ancestors.has(value)) { | ||
| return '[Circular]'; | ||
| } | ||
| ancestors.add(value); | ||
|
|
||
| try { | ||
| if (Array.isArray(value)) { | ||
| return value.map((item) => this.redactConfig(item, ignoreList, ancestors)); | ||
| } | ||
|
|
||
| const result: Record<string, unknown> = {}; | ||
| for (const key of Object.keys(value)) { | ||
| result[key] = this.shouldRedactConfigKey(key, ignoreList) | ||
| ? redactedValue | ||
| : this.redactConfig((value as Record<string, unknown>)[key], ignoreList, ancestors); | ||
| } | ||
| return result; | ||
| } finally { | ||
| ancestors.delete(value); | ||
| } | ||
| } | ||
|
|
||
| shouldRedactConfigKey(key: string, ignoreList: (string | RegExp)[]): boolean { | ||
| return ignoreList.some((item) => (typeof item === 'string' ? item === key : item.test(key))); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.