Remove over-engineered sanitizeError function (#21750)

This commit is contained in:
Pascal Jufer
2024-03-08 21:42:28 +01:00
committed by GitHub
parent 5cc89ef430
commit ce7ce211f8
3 changed files with 3 additions and 41 deletions

View File

@@ -21,7 +21,6 @@ import { getSchema } from './utils/get-schema.js';
import { JobQueue } from './utils/job-queue.js';
import { mapValuesDeep } from './utils/map-values-deep.js';
import { redactObject } from './utils/redact-object.js';
import { sanitizeError } from './utils/sanitize-error.js';
import { scheduleSynchronizedJob, validateCron } from './utils/schedule.js';
import { isSystemCollection } from '@directus/system-data';
@@ -450,8 +449,9 @@ class FlowManager {
let data;
if (error instanceof Error) {
// make sure we don't expose the stack trace
data = sanitizeError(error);
// Don't expose the stack trace to the next operation
delete error.stack;
data = error;
} else if (typeof error === 'string') {
// If the error is a JSON string, parse it and use that as the error data
data = isValidJSON(error) ? parseJSON(error) : error;

View File

@@ -1,30 +0,0 @@
import { createError } from '@directus/errors';
import { describe, expect, test } from 'vitest';
import { sanitizeError } from './sanitize-error.js';
describe('sanitizeError', () => {
test('removes stack trace from Error', () => {
const error = new Error('test message', {
cause: 'test',
});
const result = sanitizeError(error);
expect(result.stack).toBe(undefined);
expect(result.message).toBe(error.message);
expect(result.cause).toBe(error.cause);
});
test('removes stack trace from DirectusError', () => {
const DummyError = createError<{ more: string }>('TEAPOT', 'test message', 418);
const error = new DummyError({ more: 'info' });
const result = sanitizeError(error);
expect(result.stack).toBe(undefined);
expect(result.message).toBe(error.message);
expect(result.code).toBe(error.code);
expect(result.status).toBe(error.status);
expect(result.extensions).toStrictEqual(result.extensions);
});
});

View File

@@ -1,8 +0,0 @@
export function sanitizeError<T extends Error>(error: T): T {
// clear the stack
if (error.stack !== undefined) {
delete error.stack;
}
return error;
}