Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ yarn-debug.log*
yarn-error.log*
node.log

# Core dumps
core
core.*

# Dependency directories
node_modules/
.pnpm-store/
Expand Down
6 changes: 6 additions & 0 deletions packages/toolshed/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @graphprotocol/toolshed

## 1.0.3

### Patch Changes

- Add fn to parse custom errors to toolshed package

## 1.0.2

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/toolshed/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@graphprotocol/toolshed",
"version": "1.0.2",
"version": "1.0.3",
"publishConfig": {
"access": "public"
},
Expand Down
31 changes: 31 additions & 0 deletions packages/toolshed/src/core/custom-errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { getInterface } from '@graphprotocol/interfaces'
import { ErrorDescription } from 'ethers'

export function parseCustomError(error: string): string | null {
const interfaces = [
getInterface('HorizonStaking'),
getInterface('SubgraphService'),
getInterface('PaymentsEscrow'),
getInterface('GraphTallyCollector'),
getInterface('GraphPayments'),
]

let decodedError: ErrorDescription | null = null
for (const iface of interfaces) {
decodedError = iface.parseError(error)
if (decodedError) {
break
}
}

if (!decodedError) {
return null
}

const argStrings = decodedError.fragment.inputs.map((input, i) => {
const value = decodedError.args[i]
return `${input.name}: ${value}`
})

return `${decodedError.name}(${argStrings.join(', ')})`
}
1 change: 1 addition & 0 deletions packages/toolshed/src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export * from './accounts'
export * from './allocation'
export * from './attestations'
export * from './constants'
export * from './custom-errors'
export * from './disputes'
export * from './graph-tally'
export * from './poi'
Expand Down