check array length and only add newlines if length > 0
Signed-off-by: Max Falk <gmdfalk@gmail.com>
This commit is contained in:
@@ -23,6 +23,16 @@ describe('formatErrorMessage with esbuild plugin error', () => {
|
||||
plugin: 'esbuild',
|
||||
message: 'test',
|
||||
});
|
||||
expect(msg).toBe('test\n\n');
|
||||
expect(msg).toBe('test');
|
||||
});
|
||||
it('given error with errors array then error message should have new lines', () => {
|
||||
const msg = formatErrorMessage({
|
||||
code: 'PLUGIN_ERROR',
|
||||
plugin: 'esbuild',
|
||||
message: 'test',
|
||||
id: 'index.js',
|
||||
errors: [{ text: 'Dummy', location: { line: 1, column: 1 } }],
|
||||
});
|
||||
expect(msg).toContain('test\n\n');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -27,8 +27,9 @@ export function formatErrorMessage(error: any) {
|
||||
|
||||
if (error.code === 'PLUGIN_ERROR') {
|
||||
if (error.plugin === 'esbuild') {
|
||||
msg += `${error.message}\n\n`;
|
||||
if (error.errors) {
|
||||
msg += `${error.message}`;
|
||||
if (error.errors?.length) {
|
||||
msg += `\n\n`;
|
||||
for (const { text, location } of error.errors) {
|
||||
const { line, column } = location;
|
||||
const path = relativePath(paths.targetDir, error.id);
|
||||
|
||||
Reference in New Issue
Block a user