@@ -50,7 +50,7 @@ import {
5050 type PluginActivation ,
5151 type PluginApiServices ,
5252} from "./PluginApi.ts" ;
53- import { errorText , PluginCodeError , pluginCodeScope } from "./api/facade.ts" ;
53+ import { errorText , isPluginCodeError , PluginCodeError , pluginCodeScope } from "./api/facade.ts" ;
5454import { makePluginFailureGuard } from "./pluginFailureGuard.ts" ;
5555import { makePluginFailures } from "./pluginFailures.ts" ;
5656import { discoverPlugins , type DiscoveredPlugin } from "./pluginDiscovery.ts" ;
@@ -236,6 +236,12 @@ interface Found {
236236// absolute path loads files from disk in both, and plugin code resolves its own imports.
237237const requireFromDisk = NodeModule . createRequire ( process . execPath ) ;
238238
239+ // A failed plugin's row shows the plugin's own error text, a deliberate exception to fixed messages.
240+ const pluginFailureText = ( cause : Cause . Cause < PluginCodeError > ) => {
241+ const error = Cause . squash ( cause ) ;
242+ return errorText ( isPluginCodeError ( error ) ? error . cause : error ) ;
243+ } ;
244+
239245const isPluginDefinition = ( value : unknown ) : value is PluginDefinition =>
240246 typeof value === "object" &&
241247 value !== null &&
@@ -332,11 +338,14 @@ const make = Effect.gen(function* () {
332338 const runCleanup = ( pluginId : PluginId , cleanup : ( ) => void | Promise < void > ) =>
333339 Effect . tryPromise ( {
334340 try : ( ) => pluginCodeScope . run ( pluginId , ( ) => Promise . resolve ( ) . then ( cleanup ) ) ,
335- catch : ( cause ) => new PluginCodeError ( { cause } ) ,
341+ catch : ( cause ) => new PluginCodeError ( { pluginId , stage : "cleanup" , cause } ) ,
336342 } ) . pipe (
337343 Effect . catchTags ( {
338344 PluginCodeError : ( error ) =>
339- Effect . logWarning ( "plugin cleanup failed" , { pluginId, reason : error . message } ) ,
345+ Effect . logWarning ( "plugin cleanup failed" , {
346+ pluginId,
347+ reason : errorText ( error . cause ) ,
348+ } ) ,
340349 } ) ,
341350 ) ;
342351
@@ -382,7 +391,7 @@ const make = Effect.gen(function* () {
382391 }
383392 return definition ;
384393 } ,
385- catch : ( cause ) => new PluginCodeError ( { cause } ) ,
394+ catch : ( cause ) => new PluginCodeError ( { pluginId : plugin . id , stage : "load" , cause } ) ,
386395 } ) ;
387396
388397 const activatePlugin = Effect . fn ( "PluginHost.activate" ) ( function * ( plugin : DiscoveredPlugin ) {
@@ -433,7 +442,7 @@ const make = Effect.gen(function* () {
433442 if ( definition . _tag === "Failure" ) {
434443 return yield * setRecord ( plugin . id , {
435444 status : "failed" ,
436- failure : { stage : "load" , message : errorText ( Cause . squash ( definition . cause ) ) } ,
445+ failure : { stage : "load" , message : pluginFailureText ( definition . cause ) } ,
437446 } ) ;
438447 }
439448 const activation = makePluginActivation ( ) ;
@@ -456,7 +465,8 @@ const make = Effect.gen(function* () {
456465 pluginCodeScope . run ( plugin . id , ( ) =>
457466 Promise . resolve ( ) . then ( ( ) => definition . value . activate ( api ) ) ,
458467 ) ,
459- catch : ( cause ) => new PluginCodeError ( { cause } ) ,
468+ catch : ( cause ) =>
469+ new PluginCodeError ( { pluginId : plugin . id , stage : "activate" , cause } ) ,
460470 } ) . pipe ( Effect . timeoutOption ( ACTIVATE_DEADLINE ) ) ,
461471 ) . pipe ( Effect . exit ) ;
462472 if ( activated . _tag === "Success" && Option . isSome ( activated . value ) ) {
@@ -472,7 +482,7 @@ const make = Effect.gen(function* () {
472482 stage : "activate" ,
473483 message :
474484 activated . _tag === "Failure"
475- ? errorText ( Cause . squash ( activated . cause ) )
485+ ? pluginFailureText ( activated . cause )
476486 : `activate did not finish within ${ Duration . toSeconds ( ACTIVATE_DEADLINE ) } seconds.` ,
477487 } ,
478488 } ) ;
0 commit comments