Skip to content

Commit c553ed7

Browse files
amankansal-ltclaude
andcommitted
fix(kernel): require a real Error behind the AppError brand
A plain object carrying the global brand symbol passed instanceof AppError and left normalizeError with no code or message. Package copies share the realm's Error.prototype, so the plugin-copy case still holds. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 229bf7e commit c553ed7

2 files changed

Lines changed: 4 additions & 5 deletions

File tree

‎packages/kernel/src/errors.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@ test('bundled plugin errors preserve codes and details without changing subclass
191191
assert.deepEqual(normalized.details, { provider: 'example' });
192192
const ordinary = Object.assign(new Error('bad plugin profile'), { code: 'INVALID_ARGS' });
193193
assert.equal(ordinary instanceof AppError, false);
194+
const forged = { [Symbol.for('agent-device.AppError')]: true };
195+
assert.equal(forged instanceof AppError, false);
196+
assert.equal(normalizeError(forged).code, 'UNKNOWN');
194197
class SpecificError extends AppError {}
195198
assert.ok(new SpecificError('COMMAND_FAILED', 'specific') instanceof SpecificError);
196199
assert.equal(foreign instanceof SpecificError, false);

‎packages/kernel/src/errors.ts‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,7 @@ const APP_ERROR_BRAND = Symbol.for('agent-device.AppError');
4141
export class AppError extends Error {
4242
static [Symbol.hasInstance](value: unknown): boolean {
4343
if (this !== AppError) return Function.prototype[Symbol.hasInstance].call(this, value);
44-
return (
45-
typeof value === 'object' &&
46-
value !== null &&
47-
(value as Record<symbol, unknown>)[APP_ERROR_BRAND] === true
48-
);
44+
return value instanceof Error && (value as Record<symbol, unknown>)[APP_ERROR_BRAND] === true;
4945
}
5046

5147
code: AppErrorCode;

0 commit comments

Comments
 (0)