Skip to content

Commit 7d0abe0

Browse files
authored
Merge pull request #1251 from graphprotocol/tmigone/custom-error
2 parents 561cf59 + 86e05e2 commit 7d0abe0

File tree

5 files changed

+39
-5
lines changed

5 files changed

+39
-5
lines changed

.gitignore

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ yarn-debug.log*
33
yarn-error.log*
44
node.log
55

6-
# Core dumps
7-
core
8-
core.*
9-
106
# Dependency directories
117
node_modules/
128
.pnpm-store/

packages/toolshed/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @graphprotocol/toolshed
22

3+
## 1.0.3
4+
5+
### Patch Changes
6+
7+
- Add fn to parse custom errors to toolshed package
8+
39
## 1.0.2
410

511
### Patch Changes

packages/toolshed/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@graphprotocol/toolshed",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"publishConfig": {
55
"access": "public"
66
},
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { getInterface } from '@graphprotocol/interfaces'
2+
import { ErrorDescription } from 'ethers'
3+
4+
export function parseCustomError(error: string): string | null {
5+
const interfaces = [
6+
getInterface('HorizonStaking'),
7+
getInterface('SubgraphService'),
8+
getInterface('PaymentsEscrow'),
9+
getInterface('GraphTallyCollector'),
10+
getInterface('GraphPayments'),
11+
]
12+
13+
let decodedError: ErrorDescription | null = null
14+
for (const iface of interfaces) {
15+
decodedError = iface.parseError(error)
16+
if (decodedError) {
17+
break
18+
}
19+
}
20+
21+
if (!decodedError) {
22+
return null
23+
}
24+
25+
const argStrings = decodedError.fragment.inputs.map((input, i) => {
26+
const value = decodedError.args[i]
27+
return `${input.name}: ${value}`
28+
})
29+
30+
return `${decodedError.name}(${argStrings.join(', ')})`
31+
}

packages/toolshed/src/core/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export * from './accounts'
22
export * from './allocation'
33
export * from './attestations'
44
export * from './constants'
5+
export * from './custom-errors'
56
export * from './disputes'
67
export * from './graph-tally'
78
export * from './poi'

0 commit comments

Comments
 (0)