Have assertError delegate to isError in @backstage/errors

Simplify the assertError implementation by delegating to isError
instead of duplicating the same validation checks.

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
Made-with: Cursor
This commit is contained in:
Patrik Oldsberg
2026-04-13 13:19:22 +02:00
parent 8055219d27
commit 608c1e5958
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}'`);
}
}