@@ -3,7 +3,7 @@ import { request } from 'undici';
33import { IndexerController } from './controller-client/controller.client.js' ;
44import { printHeapStats , printMemoryUsage , printUsageMap } from './stats.control.js' ;
55import { AccountSynchronizer } from './sync-modules/sync-accounts.js' ;
6- import { ContractStateSynchronizer } from './sync-modules/sync-contract-state.js' ;
6+ import { ConfigLoadError , ContractStateSynchronizer } from './sync-modules/sync-contract-state.js' ;
77import { ProposalSynchronizer } from './sync-modules/sync-proposals.js' ;
88import { VoterSynchronizer } from './sync-modules/sync-voters.js' ;
99import { QueueManager } from './queue-manager/queue.manager.js' ;
@@ -59,15 +59,27 @@ async function syncProposals(chain: string, host?: string) {
5959 await syncWithPauseResume ( chain , 'table-proposals' , new ProposalSynchronizer ( chain ) , host ) ;
6060}
6161
62- async function syncContractState ( chain : string , host ?: string , contract ?: string , table ?: string ) {
63- const contractStateSynchronizer = new ContractStateSynchronizer ( chain ) ;
62+ type ContractStateSyncResult = 'synced' | 'disabled' | 'config-error' ;
63+
64+ async function syncContractState ( chain : string , host ?: string , contract ?: string , table ?: string ) : Promise < ContractStateSyncResult > {
65+ let contractStateSynchronizer : ContractStateSynchronizer ;
66+ try {
67+ contractStateSynchronizer = new ContractStateSynchronizer ( chain ) ;
68+ } catch ( error ) {
69+ if ( error instanceof ConfigLoadError ) {
70+ console . error ( `\n❌ Contract state sync skipped: ${ error . message } ` ) ;
71+ console . error ( ` Fix the config file above and re-run the sync.` ) ;
72+ return 'config-error' ;
73+ }
74+ throw error ;
75+ }
6476 // Check if contract state is enabled before proceeding
6577 if ( ! contractStateSynchronizer . isEnabled ( ) ) {
6678 console . log ( `Contract state synchronization is not enabled for chain: ${ chain } ` ) ;
67- return false ; // Return false to indicate no sync was performed
79+ return 'disabled' ;
6880 }
6981 await syncWithPauseResume ( chain , 'dynamic-table' , contractStateSynchronizer , host , contract , table ) ;
70- return true ; // Return true to indicate sync was performed
82+ return 'synced' ;
7183}
7284
7385async function stopIndexer ( chain : string , host ?: string ) {
@@ -550,14 +562,17 @@ async function getScalingInfo(chain: string, host?: string) {
550562 . description ( 'Sync contract state for a specific chain' )
551563 . action ( async ( chain : string , contract ?: string , table ?: string , args ?: any ) => {
552564 try {
553- const syncPerformed = await syncContractState ( chain , args . host , contract , table ) ;
554- // Only show completion message if sync was actually performed
555- if ( syncPerformed ) {
565+ const result = await syncContractState ( chain , args . host , contract , table ) ;
566+ if ( result === 'synced' ) {
556567 console . log ( 'Sync completed for contractState' ) ;
557- } else {
568+ process . exit ( 0 ) ;
569+ } else if ( result === 'disabled' ) {
558570 console . log ( 'Contract state synchronization skipped - feature is disabled in config' ) ;
571+ process . exit ( 0 ) ;
572+ } else {
573+ // config-error: actionable message already printed by syncContractState
574+ process . exit ( 1 ) ;
559575 }
560- process . exit ( 0 ) ;
561576 } catch ( error ) {
562577 console . error ( 'Error syncing contract state:' , error ) ;
563578 process . exit ( 1 ) ;
@@ -571,11 +586,16 @@ async function getScalingInfo(chain: string, host?: string) {
571586 await syncVoters ( chain ) ;
572587 await syncAccounts ( chain , undefined , undefined ) ;
573588 await syncProposals ( chain ) ;
574- const contractStateSynced = await syncContractState ( chain ) ;
589+ const contractStateResult = await syncContractState ( chain ) ;
575590
576- console . log ( `Sync completed for all components` ) ;
577- if ( ! contractStateSynced ) {
578- console . log ( `Note: Contract state sync was skipped (feature is disabled in config)` ) ;
591+ if ( contractStateResult === 'config-error' ) {
592+ console . log ( `Sync completed for voters, accounts and proposals.` ) ;
593+ console . log ( `Note: Contract state sync was skipped due to an invalid config (see error above).` ) ;
594+ } else {
595+ console . log ( `Sync completed for all components` ) ;
596+ if ( contractStateResult === 'disabled' ) {
597+ console . log ( `Note: Contract state sync was skipped (feature is disabled in config)` ) ;
598+ }
579599 }
580600 } catch ( error ) {
581601 console . error ( 'Error during sync:' , error ) ;
0 commit comments