refactor(core): Switch plain errors in cli to ApplicationError (#7857)

Ensure all errors in `cli` are `ApplicationError` or children of it and
contain no variables in the message, to continue normalizing all the
errors we report to Sentry

Follow-up to: https://github.com/n8n-io/n8n/pull/7839
This commit is contained in:
Iván Ovejero
2023-11-29 12:25:10 +01:00
committed by GitHub
parent 87def60979
commit c08c5cc37b
58 changed files with 277 additions and 195 deletions

View File

@@ -1,3 +1,4 @@
import { ApplicationError } from 'n8n-workflow';
import { LdapService } from './LdapService.ee';
import { LdapSync } from './LdapSync.ee';
import type { LdapConfig } from './types';
@@ -15,7 +16,7 @@ export class LdapManager {
sync: LdapSync;
} {
if (!this.initialized) {
throw new Error('LDAP Manager has not been initialized');
throw new ApplicationError('LDAP Manager has not been initialized');
}
return this.ldap;
}

View File

@@ -4,6 +4,7 @@ import type { LdapConfig } from './types';
import { formatUrl, getMappingAttributes } from './helpers';
import { BINARY_AD_ATTRIBUTES } from './constants';
import type { ConnectionOptions } from 'tls';
import { ApplicationError } from 'n8n-workflow';
export class LdapService {
private client: Client | undefined;
@@ -25,7 +26,7 @@ export class LdapService {
*/
private async getClient() {
if (this._config === undefined) {
throw new Error('Service cannot be used without setting the property config');
throw new ApplicationError('Service cannot be used without setting the property config');
}
if (this.client === undefined) {
const url = formatUrl(

View File

@@ -17,6 +17,7 @@ import type { RunningMode, SyncStatus } from '@db/entities/AuthProviderSyncHisto
import { Container } from 'typedi';
import { InternalHooks } from '@/InternalHooks';
import { Logger } from '@/Logger';
import { ApplicationError } from 'n8n-workflow';
export class LdapSync {
private intervalId: NodeJS.Timeout | undefined = undefined;
@@ -64,7 +65,7 @@ export class LdapSync {
*/
scheduleRun(): void {
if (!this._config.synchronizationInterval) {
throw new Error('Interval variable has to be defined');
throw new ApplicationError('Interval variable has to be defined');
}
this.intervalId = setInterval(async () => {
await this.run('live');

View File

@@ -20,7 +20,7 @@ import {
LDAP_LOGIN_LABEL,
} from './constants';
import type { ConnectionSecurity, LdapConfig } from './types';
import { jsonParse } from 'n8n-workflow';
import { ApplicationError, jsonParse } from 'n8n-workflow';
import { License } from '@/License';
import { InternalHooks } from '@/InternalHooks';
import {
@@ -157,7 +157,7 @@ export const updateLdapConfig = async (ldapConfig: LdapConfig): Promise<void> =>
const { valid, message } = validateLdapConfigurationSchema(ldapConfig);
if (!valid) {
throw new Error(message);
throw new ApplicationError(message);
}
if (ldapConfig.loginEnabled && getCurrentAuthenticationMethod() === 'saml') {