fix(init): rethrow plugin activation failures with the original error as cause so the originating frame survives to the caller

This commit is contained in:
David Snelling 2026-08-27 12:07:09 -07:00
parent 4c7b0fab7a
commit 2496e09aeb

View file

@ -1815,7 +1815,11 @@ export class Brainy<T = any> implements BrainyInterface<T> {
if (error instanceof Error && (error as Error & { code?: string }).code === 'BRAINY_WRITER_LOCKED') { if (error instanceof Error && (error as Error & { code?: string }).code === 'BRAINY_WRITER_LOCKED') {
throw error throw error
} }
throw new Error(`Failed to initialize Brainy: ${error}`) // Wrap with the original as `cause` so the originating frame (a plugin's
// own file:line, e.g. a provider boot failure) survives to the caller's
// log — a plain string interpolation discards both stack and cause.
const message = error instanceof Error ? error.message : String(error)
throw new Error(`Failed to initialize Brainy: ${message}`, { cause: error })
} }
} }