From b62f4eb0163fd2dea32a56577da9bd7453aa9db0 Mon Sep 17 00:00:00 2001 From: Ruben Taelman Date: Wed, 23 Sep 2020 09:30:33 +0200 Subject: [PATCH] change: improve getLoggerFactoryOrThrow error message --- src/logging/LazyLoggerFactory.ts | 2 +- test/unit/logging/LazyLogger.test.ts | 2 +- test/unit/logging/LazyLoggerFactory.test.ts | 4 ++-- test/unit/logging/LogUtil.test.ts | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/logging/LazyLoggerFactory.ts b/src/logging/LazyLoggerFactory.ts index cfbc2a8f2..6444d81eb 100644 --- a/src/logging/LazyLoggerFactory.ts +++ b/src/logging/LazyLoggerFactory.ts @@ -34,7 +34,7 @@ export class LazyLoggerFactory implements LoggerFactory { public getLoggerFactoryOrThrow(): LoggerFactory { if (!this.loggerFactory) { - throw new Error('Illegal logging during initialization'); + throw new Error('No logger factory has been set yet. Can be caused logger invocation during initialization.'); } return this.loggerFactory; } diff --git a/test/unit/logging/LazyLogger.test.ts b/test/unit/logging/LazyLogger.test.ts index b69c60903..b565356e8 100644 --- a/test/unit/logging/LazyLogger.test.ts +++ b/test/unit/logging/LazyLogger.test.ts @@ -12,7 +12,7 @@ describe('LazyLogger', (): void => { it('throws when no logger factory is set in the lazy logger factory.', async(): Promise => { expect((): any => logger.log('debug', 'my message', { abc: true })) - .toThrow(new Error('Illegal logging during initialization')); + .toThrow(new Error('No logger factory has been set yet. Can be caused logger invocation during initialization.')); }); it('creates a new logger using the factory.', async(): Promise => { diff --git a/test/unit/logging/LazyLoggerFactory.test.ts b/test/unit/logging/LazyLoggerFactory.test.ts index a53a9da38..a8e9cfbeb 100644 --- a/test/unit/logging/LazyLoggerFactory.test.ts +++ b/test/unit/logging/LazyLoggerFactory.test.ts @@ -31,7 +31,7 @@ describe('LazyLoggerFactory', (): void => { it('throws when retrieving the inner factory if none has been set.', async(): Promise => { expect((): any => LazyLoggerFactory.getInstance().getLoggerFactoryOrThrow()) - .toThrow(new Error('Illegal logging during initialization')); + .toThrow(new Error('No logger factory has been set yet. Can be caused logger invocation during initialization.')); }); it('Returns the inner factory if one has been set.', async(): Promise => { @@ -60,6 +60,6 @@ describe('LazyLoggerFactory', (): void => { it('errors on invoking LazyLoggers if a factory has not been set yet.', async(): Promise => { const logger = LazyLoggerFactory.getInstance().createLogger('MyLabel'); expect((): any => logger.log('debug', 'my message', { abc: true })) - .toThrow(new Error('Illegal logging during initialization')); + .toThrow(new Error('No logger factory has been set yet. Can be caused logger invocation during initialization.')); }); }); diff --git a/test/unit/logging/LogUtil.test.ts b/test/unit/logging/LogUtil.test.ts index 6322a0d83..803f1d3c8 100644 --- a/test/unit/logging/LogUtil.test.ts +++ b/test/unit/logging/LogUtil.test.ts @@ -28,6 +28,6 @@ describe('LogUtil', (): void => { expect(setGlobalLoggerFactory(new VoidLoggerFactory())); expect(setGlobalLoggerFactory(undefined)); expect((): any => LazyLoggerFactory.getInstance().getLoggerFactoryOrThrow()) - .toThrow(new Error('Illegal logging during initialization')); + .toThrow(new Error('No logger factory has been set yet. Can be caused logger invocation during initialization.')); }); });