@@ -63,6 +63,8 @@ import {
6363 notEmpty ,
6464 canonicalJsonBytes ,
6565 cachedDecode ,
66+ type MiLogger ,
67+ ConsoleLoggerAdapter ,
6668} from "@milaboratories/ts-helpers" ;
6769import type { ProjectHelper } from "../model/project_helper" ;
6870import {
@@ -119,6 +121,7 @@ class BlockInfo {
119121 public readonly fields : BlockFieldStates ,
120122 public readonly config : BlockConfig ,
121123 public readonly source : BlockPackSpec ,
124+ private readonly logger : MiLogger = new ConsoleLoggerAdapter ( ) ,
122125 ) { }
123126
124127 public check ( ) {
@@ -200,7 +203,7 @@ class BlockInfo {
200203 try {
201204 return this . blockStorageC ( ) ;
202205 } catch ( e ) {
203- console . error ( " Error getting blockStorage:" , e ) ;
206+ this . logger . error ( new Error ( `Error getting blockStorage for ${ this . id } ` , { cause : e } ) ) ;
204207 return undefined ;
205208 }
206209 }
@@ -595,6 +598,9 @@ export class ProjectMutator {
595598 ) : { args ?: unknown ; uiState ?: unknown } {
596599 const info = this . getBlockInfo ( blockId ) ;
597600 const currentState = info . blockStorage as { args ?: unknown ; uiState ?: unknown } | undefined ;
601+ if ( currentState === undefined ) {
602+ throw new Error ( `Cannot merge block state for ${ blockId } : blockStorage is unavailable` ) ;
603+ }
598604 return { ...currentState , ...partialUpdate } ;
599605 }
600606
@@ -653,9 +659,17 @@ export class ProjectMutator {
653659 ) ;
654660 if ( prerunArgs !== undefined ) {
655661 this . setBlockFieldObj ( blockId , "currentPrerunArgs" , this . createJsonFieldValue ( prerunArgs ) ) ;
662+ } else {
663+ this . deleteBlockFields ( blockId , "currentPrerunArgs" ) ;
656664 }
657665 } else {
666+ if ( info . fields . currentPrerunArgs !== undefined ) {
667+ this . projectHelper . logger . warn (
668+ `[staging] ${ blockId } : currentPrerunArgs cleared (args derivation failed)` ,
669+ ) ;
670+ }
658671 this . deleteBlockFields ( blockId , "currentArgs" ) ;
672+ this . deleteBlockFields ( blockId , "currentPrerunArgs" ) ;
659673 }
660674 }
661675
@@ -756,10 +770,7 @@ export class ProjectMutator {
756770 prerunArgsData ,
757771 ) ;
758772 } else {
759- // prerunArgs is undefined - check if we previously had one
760- if ( info . fields . currentPrerunArgs !== undefined ) {
761- prerunArgsChanged = true ;
762- }
773+ this . deleteBlockFields ( req . blockId , "currentPrerunArgs" ) ;
763774 }
764775
765776 blockChanged = true ;
@@ -903,6 +914,7 @@ export class ProjectMutator {
903914 { } ,
904915 extractConfig ( spec . blockPack . config ) ,
905916 spec . blockPack . source ,
917+ this . projectHelper . logger ,
906918 ) ;
907919 this . blockInfos . set ( blockId , info ) ;
908920
@@ -1006,7 +1018,13 @@ export class ProjectMutator {
10061018 }
10071019
10081020 private initializeBlockDuplicate ( blockId : string , originalBlockInfo : BlockInfo ) {
1009- const info = new BlockInfo ( blockId , { } , originalBlockInfo . config , originalBlockInfo . source ) ;
1021+ const info = new BlockInfo (
1022+ blockId ,
1023+ { } ,
1024+ originalBlockInfo . config ,
1025+ originalBlockInfo . source ,
1026+ this . projectHelper . logger ,
1027+ ) ;
10101028
10111029 this . blockInfos . set ( blockId , info ) ;
10121030
@@ -1210,7 +1228,12 @@ export class ProjectMutator {
12101228 "currentPrerunArgs" ,
12111229 this . createJsonFieldValue ( prerunArgs ) ,
12121230 ) ;
1231+ } else {
1232+ this . deleteBlockFields ( blockId , "currentPrerunArgs" ) ;
12131233 }
1234+ } else {
1235+ this . deleteBlockFields ( blockId , "currentArgs" ) ;
1236+ this . deleteBlockFields ( blockId , "currentPrerunArgs" ) ;
12141237 }
12151238 } ;
12161239
@@ -1250,7 +1273,9 @@ export class ProjectMutator {
12501273 ) ;
12511274 }
12521275
1253- console . log ( `[migrateBlockPack] Block ${ blockId } : ${ migrationResult . info } ` ) ;
1276+ this . projectHelper . logger . info (
1277+ `[migrateBlockPack] Block ${ blockId } : ${ migrationResult . info } ` ,
1278+ ) ;
12541279 applyStorageAndDeriveArgs ( migrationResult . newStorageJson ) ;
12551280 } else {
12561281 // Legacy blocks (modelAPIVersion 1): persist block pack, set prerunArgs = currentArgs
@@ -1413,9 +1438,14 @@ export class ProjectMutator {
14131438 // meaning staging already rendered
14141439 return ;
14151440 if ( lagThreshold === undefined || lag <= lagThreshold ) {
1416- // console.log(`[refreshStagings] RENDER staging for ${blockId} (lag=${lag})`);
1417- this . renderStagingFor ( blockId ) ;
1418- rendered ++ ;
1441+ try {
1442+ this . renderStagingFor ( blockId ) ;
1443+ rendered ++ ;
1444+ } catch ( e ) {
1445+ this . projectHelper . logger . error (
1446+ new Error ( `[refreshStagings] renderStagingFor failed for ${ blockId } ` , { cause : e } ) ,
1447+ ) ;
1448+ }
14191449 }
14201450 } ) ;
14211451 if ( rendered > 0 ) this . resetStagingRefreshTimestamp ( ) ;
@@ -1654,7 +1684,10 @@ export class ProjectMutator {
16541684
16551685 const blockInfos = new Map < string , BlockInfo > ( ) ;
16561686 blockInfoStates . forEach ( ( { id, fields, blockConfig, blockPack } ) =>
1657- blockInfos . set ( id , new BlockInfo ( id , fields , notEmpty ( blockConfig ) , notEmpty ( blockPack ) ) ) ,
1687+ blockInfos . set (
1688+ id ,
1689+ new BlockInfo ( id , fields , notEmpty ( blockConfig ) , notEmpty ( blockPack ) , projectHelper . logger ) ,
1690+ ) ,
16581691 ) ;
16591692
16601693 // check consistency of project state
0 commit comments