Merge pull request #33866 from backstage/rugvip/assert-error-delegate-to-is-error

Have `assertError` delegate to `isError` in `@backstage/errors`
This commit is contained in:
Patrik Oldsberg
2026-04-13 13:49:37 +02:00
committed by GitHub
2 changed files with 7 additions and 11 deletions
@@ -0,0 +1,5 @@
---
'@backstage/errors': patch
---
Simplified `assertError` to delegate to `isError` instead of duplicating the same checks.
+2 -11
View File
@@ -58,17 +58,8 @@ export function isError(value: unknown): value is ErrorLike {
* @param value - an unknown value
*/
export function assertError(value: unknown): asserts value is ErrorLike {
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
throw new Error(`Encountered invalid error, not an object, got '${value}'`);
}
const maybe = value as Partial<ErrorLike>;
if (typeof maybe.name !== 'string' || maybe.name === '') {
throw new Error(`Encountered error object without a name, got '${value}'`);
}
if (typeof maybe.message !== 'string') {
throw new Error(
`Encountered error object without a message, got '${value}'`,
);
if (!isError(value)) {
throw new Error(`Encountered invalid error, got '${value}'`);
}
}