mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-11 12:57:29 -08:00
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
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:
parent
5b925bcf10
commit
3ff902feb9
|
@ -6,6 +6,7 @@ export class FeatureNotLicensedError extends ApplicationError {
|
||||||
constructor(feature: (typeof LICENSE_FEATURES)[keyof typeof LICENSE_FEATURES]) {
|
constructor(feature: (typeof LICENSE_FEATURES)[keyof typeof LICENSE_FEATURES]) {
|
||||||
super(
|
super(
|
||||||
`Your license does not allow for ${feature}. To enable ${feature}, please upgrade to a license that supports this feature.`,
|
`Your license does not allow for ${feature}. To enable ${feature}, please upgrade to a license that supports this feature.`,
|
||||||
|
{ level: 'warning' },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,10 @@ export class ErrorReporter {
|
||||||
const context = executionId ? ` (execution ${executionId})` : '';
|
const context = executionId ? ` (execution ${executionId})` : '';
|
||||||
|
|
||||||
do {
|
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;
|
const meta = e instanceof ApplicationError ? e.extra : undefined;
|
||||||
this.logger.error(msg, meta);
|
this.logger.error(msg, meta);
|
||||||
e = e.cause as Error;
|
e = e.cause as Error;
|
||||||
|
|
|
@ -5,6 +5,7 @@ import { mock } from 'jest-mock-extended';
|
||||||
import { ApplicationError } from 'n8n-workflow';
|
import { ApplicationError } from 'n8n-workflow';
|
||||||
|
|
||||||
import { ErrorReporter } from '@/error-reporter';
|
import { ErrorReporter } from '@/error-reporter';
|
||||||
|
import type { Logger } from '@/logging/logger';
|
||||||
|
|
||||||
jest.mock('@sentry/node', () => ({
|
jest.mock('@sentry/node', () => ({
|
||||||
init: jest.fn(),
|
init: jest.fn(),
|
||||||
|
@ -101,4 +102,29 @@ describe('ErrorReporter', () => {
|
||||||
expect(result).toBeNull();
|
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);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue