Skip to content

Commit

Permalink
feat: imrpove exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
saihaj committed Jan 8, 2024
1 parent 1b78523 commit 76546a9
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
22 changes: 22 additions & 0 deletions packages/indexer-agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
startMultiNetwork,
parseNetworkSpecifications,
} from './commands/start-multi-network'
import process from 'node:process'

const MULTINETWORK_MODE: boolean =
!!process.env.INDEXER_AGENT_MULTINETWORK_MODE &&
Expand Down Expand Up @@ -70,4 +71,25 @@ async function main(): Promise<void> {
await processArgumentsAndRun(args)
}

const exceptionLogger = createLogger({
name: 'IndexerAgent',
async: false,
})

process.on('uncaughtException', (reason, promise) => {
exceptionLogger.error('Uncaught exception', {
reason,
promise,
})
process.exit(1)
})

process.on('unhandledRejection', (reason, promise) => {
exceptionLogger.error('Unhandled rejection', {
reason,
promise,
})
process.exit(1)
})

void main()
23 changes: 23 additions & 0 deletions packages/indexer-service/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,33 @@
import process from 'process'
import * as yargs from 'yargs'

import start from './commands/start'
import { createLogger } from '@graphprotocol/common-ts'

yargs
.scriptName('indexer-service')
.env('INDEXER_SERVICE')
.command(start)
.demandCommand(1, 'Choose a command from the above list')
.help().argv

const exceptionLogger = createLogger({
name: 'IndexerService',
async: false,
})

process.on('uncaughtException', (reason, promise) => {
exceptionLogger.error('Uncaught exception', {
reason,
promise,
})
process.exit(1)
})

process.on('unhandledRejection', (reason, promise) => {
exceptionLogger.error('Unhandled rejection', {
reason,
promise,
})
process.exit(1)
})

0 comments on commit 76546a9

Please sign in to comment.