Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Log errors during discovery (#132)
Browse files Browse the repository at this point in the history
* feat: log errors during discovery

* chore: bump version

* fix: properly count errors
  • Loading branch information
michalsidzej authored Feb 14, 2024
1 parent 51214a2 commit 8afb97e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
6 changes: 6 additions & 0 deletions packages/discovery/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @l2beat/discovery

## 0.42.0

### Minor Changes

- Log all the discovery errors at the end of the execution

## 0.41.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/discovery/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@l2beat/discovery",
"description": "L2Beat discovery - engine & tooling utilized for keeping an eye on L2s",
"version": "0.41.0",
"version": "0.42.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"bin": {
Expand Down
24 changes: 19 additions & 5 deletions packages/discovery/src/discovery/engine/DiscoveryEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,28 @@ export class DiscoveryEngine {
}

private checkErrors(resolved: Analysis[]): void {
let errors = 0
const errorMsgs = []
let errorCount = 0
for (const analysis of resolved) {
if (analysis.type === 'Contract') {
errors += Object.keys(analysis.errors).length
if (
analysis.type === 'Contract' &&
Object.keys(analysis.errors).length > 0
) {
const msgStart = `${analysis.name}(${analysis.address.toString()}): {`
const msgEnd = '\n}'
const errorMessages = Object.entries(analysis.errors).map(
([field, error]) => `\n\t${field}: ${error}`,
)

errorCount += errorMessages.length
errorMsgs.push([msgStart, ...errorMessages, msgEnd].join(''))
}
}
if (errors > 0) {
this.logger.logError(`Errors during discovery: ${errors}`)
if (errorCount > 0) {
this.logger.logError(`Errors during discovery: ${errorCount}`)
for (const error of errorMsgs) {
this.logger.logError(error)
}
}
}
}

0 comments on commit 8afb97e

Please sign in to comment.