From f3a3134f7e865a505afc1c27b3d479e21d809c06 Mon Sep 17 00:00:00 2001 From: Max Falk Date: Sun, 6 Jun 2021 22:26:28 +0200 Subject: [PATCH] fix(cli): fix TypeError when formatting error messages error.errors can be undefined which will lead to a TypeError, swallowing the actual error message in the process Signed-off-by: Max Falk --- packages/cli/src/lib/builder/packager.test.ts | 28 +++++++++++++++++++ packages/cli/src/lib/builder/packager.ts | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 packages/cli/src/lib/builder/packager.test.ts diff --git a/packages/cli/src/lib/builder/packager.test.ts b/packages/cli/src/lib/builder/packager.test.ts new file mode 100644 index 0000000000..69f4b4e524 --- /dev/null +++ b/packages/cli/src/lib/builder/packager.test.ts @@ -0,0 +1,28 @@ +/* + * Copyright 2021 Spotify AB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { formatErrorMessage } from './packager'; + +describe('formatErrorMessage with esbuild plugin error', () => { + it('given error with missing errors array then error message should be shown', () => { + const msg = formatErrorMessage({ + code: 'PLUGIN_ERROR', + plugin: 'esbuild', + message: 'test', + }); + expect(msg).toBe('test\n\n'); + }); +}); diff --git a/packages/cli/src/lib/builder/packager.ts b/packages/cli/src/lib/builder/packager.ts index 2c85ec3df3..d6519e79a9 100644 --- a/packages/cli/src/lib/builder/packager.ts +++ b/packages/cli/src/lib/builder/packager.ts @@ -22,7 +22,7 @@ import { paths } from '../paths'; import { makeConfigs } from './config'; import { BuildOptions } from './types'; -function formatErrorMessage(error: any) { +export function formatErrorMessage(error: any) { let msg = ''; if (error.code === 'PLUGIN_ERROR') {