Skip to content

Commit

Permalink
fix: Ensure Terminating Thread error is correctly templatized (#738)
Browse files Browse the repository at this point in the history
The error given to Stream Handler is occasionally a JSON object in
disguise, and not an Error. As a result, calling error.toString()
returns `[Object object]` rather than the error contents. I've added a
check so that if the result of toString() is the earlier value, return a
JSON.stringify result instead. Doing JSON.stringify on a proper Error
type results in `{}`. The two cases must be handled separately.

To test this, I created test indexers which called one of the two pieces
of code which throw unawaited async errors. I verified both wrote the
error message and stack trace into the log table.

```
const timeoutPromise = new Promise((_, reject) => {
  setTimeout(() => {
      reject(new Error('Error thrown after 100ms'));
  }, 100);
});
```
```context.db.IndexerStorage.upsert({}, [], []); ```
  • Loading branch information
darunrs committed May 16, 2024
1 parent 8d8a020 commit 1eac90b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions runner/src/stream-handler/stream-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ export default class StreamHandler {
indexer.setStoppedStatus().catch((e) => {
this.logger.error('Failed to set stopped status for indexer', e);
});

const streamErrorLogEntry = LogEntry.systemError(`Encountered error processing stream: ${this.indexerConfig.redisStreamKey}, terminating thread\n${error.toString()}`, this.executorContext.block_height);
const errorContent = error instanceof Error ? error.toString() : JSON.stringify(error);
const streamErrorLogEntry = LogEntry.systemError(`Encountered error processing stream: ${this.indexerConfig.redisStreamKey}, terminating thread\n${errorContent}`, this.executorContext.block_height);

indexer.writeCrashedWorkerLog(streamErrorLogEntry)
.catch((e) => {
Expand Down

0 comments on commit 1eac90b

Please sign in to comment.