@@ -60,8 +60,11 @@ export class Pico {
6060 channels : { [ eci : string ] : Channel } = { } ;
6161 rulesets : {
6262 [ rid : string ] : {
63- instance : RulesetInstance ;
6463 config : RulesetConfig ;
64+
65+ // instance may be null when it's pending startup
66+ instance : RulesetInstance | null ;
67+ startupError ?: any ;
6568 } ;
6669 } = { } ;
6770
@@ -340,6 +343,7 @@ export class Pico {
340343 const ctx = createRulesetContext ( this . pf , this , { rid, config } ) ;
341344 const instance = await rs . init ( ctx , this . pf . environment ) ;
342345 this . rulesets [ rid ] . instance = instance ;
346+ delete this . rulesets [ rid ] . startupError ;
343347 }
344348 }
345349
@@ -492,7 +496,7 @@ export class Pico {
492496 try {
493497 while ( ( this . current = this . schedule . shift ( ) ) ) {
494498 const rs = this . rulesets [ this . current . rid ] ;
495- if ( rs && rs . instance . event ) {
499+ if ( rs ? .instance ? .event ) {
496500 // must process one event at a time to maintain the pico's single-threaded guarantee
497501 const response = await rs . instance . event (
498502 this . current . event ,
@@ -510,7 +514,7 @@ export class Pico {
510514 if ( ! rs ) {
511515 throw new Error ( `Pico doesn't have ${ txn . query . rid } installed.` ) ;
512516 }
513- const qfn = rs . instance . query && rs . instance . query [ txn . query . name ] ;
517+ const qfn = rs ? .instance ? .query && rs . instance . query [ txn . query . name ] ;
514518 if ( ! qfn ) {
515519 throw new Error (
516520 `Ruleset ${ txn . query . rid } does not have query function "${ txn . query . name } "`
0 commit comments