refactor(core): Hide stack trace for warning-level errors (#12411)
Some checks are pending
Test Master / install-and-build (push) Waiting to run
Test Master / Unit tests (18.x) (push) Blocked by required conditions
Test Master / Unit tests (20.x) (push) Blocked by required conditions
Test Master / Unit tests (22.4) (push) Blocked by required conditions
Test Master / Lint (push) Blocked by required conditions
Test Master / Notify Slack on failure (push) Blocked by required conditions

This commit is contained in:
Iván Ovejero 2025-01-02 17:48:39 +01:00 committed by GitHub
parent 5b925bcf10
commit 3ff902feb9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 31 additions and 1 deletions

View file

@ -6,6 +6,7 @@ export class FeatureNotLicensedError extends ApplicationError {
constructor(feature: (typeof LICENSE_FEATURES)[keyof typeof LICENSE_FEATURES]) {
super(
`Your license does not allow for ${feature}. To enable ${feature}, please upgrade to a license that supports this feature.`,
{ level: 'warning' },
);
}
}

View file

@ -29,7 +29,10 @@ export class ErrorReporter {
const context = executionId ? ` (execution ${executionId})` : '';
do {
const msg = [e.message + context, e.stack ? `\n${e.stack}\n` : ''].join('');
const msg = [
e.message + context,
e instanceof ApplicationError && e.level === 'error' && e.stack ? `\n${e.stack}\n` : '',
].join('');
const meta = e instanceof ApplicationError ? e.extra : undefined;
this.logger.error(msg, meta);
e = e.cause as Error;

View file

@ -5,6 +5,7 @@ import { mock } from 'jest-mock-extended';
import { ApplicationError } from 'n8n-workflow';
import { ErrorReporter } from '@/error-reporter';
import type { Logger } from '@/logging/logger';
jest.mock('@sentry/node', () => ({
init: jest.fn(),
@ -101,4 +102,29 @@ describe('ErrorReporter', () => {
expect(result).toBeNull();
});
});
describe('error', () => {
let error: ApplicationError;
let logger: Logger;
let errorReporter: ErrorReporter;
const metadata = undefined;
beforeEach(() => {
error = new ApplicationError('Test error');
logger = mock<Logger>();
errorReporter = new ErrorReporter(logger);
});
it('should include stack trace for error-level `ApplicationError`', () => {
error.level = 'error';
errorReporter.error(error);
expect(logger.error).toHaveBeenCalledWith(`Test error\n${error.stack}\n`, metadata);
});
it('should exclude stack trace for warning-level `ApplicationError`', () => {
error.level = 'warning';
errorReporter.error(error);
expect(logger.error).toHaveBeenCalledWith('Test error', metadata);
});
});
});