diff --git a/.changeset/assert-error-delegate-to-is-error.md b/.changeset/assert-error-delegate-to-is-error.md new file mode 100644 index 0000000000..3b34d54c91 --- /dev/null +++ b/.changeset/assert-error-delegate-to-is-error.md @@ -0,0 +1,5 @@ +--- +'@backstage/errors': patch +--- + +Simplified `assertError` to delegate to `isError` instead of duplicating the same checks. diff --git a/packages/errors/src/errors/assertion.ts b/packages/errors/src/errors/assertion.ts index 9f5e1fae1a..ada83e4c86 100644 --- a/packages/errors/src/errors/assertion.ts +++ b/packages/errors/src/errors/assertion.ts @@ -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; - 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}'`); } }