From 4f9094caf3cc4781137b7cfccbe2e1858f4f39c0 Mon Sep 17 00:00:00 2001 From: Thomas Watson Date: Mon, 20 Nov 2023 15:23:16 +0100 Subject: [PATCH] Always throw error objects - never strings (#171498) --- preinstall_check.js | 2 +- src/plugins/console/public/lib/autocomplete/body_completer.js | 2 +- .../explorer/explorer_charts/explorer_chart_distribution.js | 2 +- x-pack/test/api_integration/apis/maps/migrations.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/preinstall_check.js b/preinstall_check.js index d6d0cdf1ffb49..59a4cfd2aa4a7 100644 --- a/preinstall_check.js +++ b/preinstall_check.js @@ -10,7 +10,7 @@ const isUsingNpm = process.env.npm_config_git !== undefined; if (isUsingNpm) { - throw `Use Yarn instead of npm, see Kibana's contributing guidelines`; + throw new Error(`Use Yarn instead of npm, see Kibana's contributing guidelines`); } // The value of the `npm_config_argv` env for each command: diff --git a/src/plugins/console/public/lib/autocomplete/body_completer.js b/src/plugins/console/public/lib/autocomplete/body_completer.js index 9759eb9b629da..d9355db85f4d8 100644 --- a/src/plugins/console/public/lib/autocomplete/body_completer.js +++ b/src/plugins/console/public/lib/autocomplete/body_completer.js @@ -266,7 +266,7 @@ function compileCondition(description, compiledObject) { return new RegExp(description.lines_regex, 'm').test(lines); }, compiledObject); } else { - throw 'unknown condition type - got: ' + JSON.stringify(description); + throw new Error(`unknown condition type - got: ${JSON.stringify(description)}`); } } diff --git a/x-pack/plugins/ml/public/application/explorer/explorer_charts/explorer_chart_distribution.js b/x-pack/plugins/ml/public/application/explorer/explorer_charts/explorer_chart_distribution.js index 51fbb39f9f733..169f739de41cd 100644 --- a/x-pack/plugins/ml/public/application/explorer/explorer_charts/explorer_chart_distribution.js +++ b/x-pack/plugins/ml/public/application/explorer/explorer_charts/explorer_chart_distribution.js @@ -177,7 +177,7 @@ export class ExplorerChartDistribution extends React.Component { .rangePoints([rowMargin, chartHeight - rowMargin]) .domain(scaleCategories); } else { - throw `chartType '${chartType}' not supported`; + throw new Error(`chartType '${chartType}' not supported`); } const yAxis = d3.svg diff --git a/x-pack/test/api_integration/apis/maps/migrations.js b/x-pack/test/api_integration/apis/maps/migrations.js index 1295dac5bbb49..30301a80577b3 100644 --- a/x-pack/test/api_integration/apis/maps/migrations.js +++ b/x-pack/test/api_integration/apis/maps/migrations.js @@ -75,7 +75,7 @@ export default function ({ getService }) { try { panels = JSON.parse(resp.body.attributes.panelsJSON); } catch (error) { - throw 'Unable to parse panelsJSON from dashboard saved object'; + throw new Error('Unable to parse panelsJSON from dashboard saved object'); } expect(panels.length).to.be(1); expect(panels[0].type).to.be('map');