From 5106be3a97f9623e6bb0a8e2dbc334336816b9e9 Mon Sep 17 00:00:00 2001 From: Bastien Caudan Date: Wed, 6 Sep 2023 14:40:42 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20early=20exit=20when=20no=20configur?= =?UTF-8?q?ation=20provided?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/logs/src/boot/logsPublicApi.spec.ts | 6 ++++++ packages/logs/src/boot/logsPublicApi.ts | 4 ++++ packages/rum-core/src/boot/rumPublicApi.spec.ts | 6 ++++++ packages/rum-core/src/boot/rumPublicApi.ts | 4 ++++ 4 files changed, 20 insertions(+) diff --git a/packages/logs/src/boot/logsPublicApi.spec.ts b/packages/logs/src/boot/logsPublicApi.spec.ts index b383e68f98..af969c5741 100644 --- a/packages/logs/src/boot/logsPublicApi.spec.ts +++ b/packages/logs/src/boot/logsPublicApi.spec.ts @@ -62,6 +62,12 @@ describe('logs entry', () => { expect(startLogs).toHaveBeenCalled() }) + it('should not start when the configuration is missing', () => { + ;(LOGS.init as () => void)() + expect(displaySpy).toHaveBeenCalled() + expect(startLogs).not.toHaveBeenCalled() + }) + it('should not start when the configuration is invalid', () => { LOGS.init(INVALID_INIT_CONFIGURATION) expect(displaySpy).toHaveBeenCalled() diff --git a/packages/logs/src/boot/logsPublicApi.ts b/packages/logs/src/boot/logsPublicApi.ts index 67144dd5d1..b4be3f79f1 100644 --- a/packages/logs/src/boot/logsPublicApi.ts +++ b/packages/logs/src/boot/logsPublicApi.ts @@ -71,6 +71,10 @@ export function makeLogsPublicApi(startLogsImpl: StartLogs) { logger: mainLogger, init: monitor((initConfiguration: LogsInitConfiguration) => { + if (!initConfiguration) { + display.error('Missing configuration') + return + } // This function should be available, regardless of initialization success. getInitConfigurationStrategy = () => deepClone(initConfiguration) diff --git a/packages/rum-core/src/boot/rumPublicApi.spec.ts b/packages/rum-core/src/boot/rumPublicApi.spec.ts index 4cb83c8e88..a23afba31f 100644 --- a/packages/rum-core/src/boot/rumPublicApi.spec.ts +++ b/packages/rum-core/src/boot/rumPublicApi.spec.ts @@ -46,6 +46,12 @@ describe('rum public api', () => { expect(startRumSpy).toHaveBeenCalled() }) + it('should not start when the configuration is missing', () => { + ;(rumPublicApi.init as () => void)() + expect(displaySpy).toHaveBeenCalled() + expect(startRumSpy).not.toHaveBeenCalled() + }) + it('should not start when the configuration is invalid', () => { rumPublicApi.init(INVALID_INIT_CONFIGURATION) expect(displaySpy).toHaveBeenCalled() diff --git a/packages/rum-core/src/boot/rumPublicApi.ts b/packages/rum-core/src/boot/rumPublicApi.ts index c0fe8d8aea..43d1099dee 100644 --- a/packages/rum-core/src/boot/rumPublicApi.ts +++ b/packages/rum-core/src/boot/rumPublicApi.ts @@ -99,6 +99,10 @@ export function makeRumPublicApi( } function initRum(initConfiguration: RumInitConfiguration) { + if (!initConfiguration) { + display.error('Missing configuration') + return + } // This function should be available, regardless of initialization success. getInitConfigurationStrategy = () => deepClone(initConfiguration)