[8.11] Always throw error objects - never strings (#171498) (#171547)

# Backport

This will backport the following commits from `main` to `8.11`:
- [Always throw error objects - never strings
(#171498)](https://github.com/elastic/kibana/pull/171498)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Thomas
Watson","email":"watson@elastic.co"},"sourceCommit":{"committedDate":"2023-11-20T14:23:16Z","message":"Always
throw error objects - never strings
(#171498)","sha":"4f9094caf3cc4781137b7cfccbe2e1858f4f39c0","branchLabelMapping":{"^v8.12.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport:all-open","v8.12.0"],"number":171498,"url":"https://github.com/elastic/kibana/pull/171498","mergeCommit":{"message":"Always
throw error objects - never strings
(#171498)","sha":"4f9094caf3cc4781137b7cfccbe2e1858f4f39c0"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.12.0","labelRegex":"^v8.12.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/171498","number":171498,"mergeCommit":{"message":"Always
throw error objects - never strings
(#171498)","sha":"4f9094caf3cc4781137b7cfccbe2e1858f4f39c0"}}]}]
BACKPORT-->

Co-authored-by: Thomas Watson <watson@elastic.co>
This commit is contained in:
Kibana Machine 2023-11-20 10:59:59 -05:00 committed by GitHub
parent 2581292e3c
commit dbf07605ac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 4 additions and 4 deletions

View file

@ -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:

View file

@ -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)}`);
}
}

View file

@ -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

View file

@ -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');