diff --git a/.gitignore b/.gitignore index 73a50607e..a66b74a8e 100644 --- a/.gitignore +++ b/.gitignore @@ -3,10 +3,6 @@ yarn-debug.log* yarn-error.log* node.log -# Core dumps -core -core.* - # Dependency directories node_modules/ .pnpm-store/ diff --git a/packages/toolshed/CHANGELOG.md b/packages/toolshed/CHANGELOG.md index 94d9a2bbd..7ff041e76 100644 --- a/packages/toolshed/CHANGELOG.md +++ b/packages/toolshed/CHANGELOG.md @@ -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 diff --git a/packages/toolshed/package.json b/packages/toolshed/package.json index 66ae55965..d7cf8edb5 100644 --- a/packages/toolshed/package.json +++ b/packages/toolshed/package.json @@ -1,6 +1,6 @@ { "name": "@graphprotocol/toolshed", - "version": "1.0.2", + "version": "1.0.3", "publishConfig": { "access": "public" }, diff --git a/packages/toolshed/src/core/custom-errors.ts b/packages/toolshed/src/core/custom-errors.ts new file mode 100644 index 000000000..2375afc2a --- /dev/null +++ b/packages/toolshed/src/core/custom-errors.ts @@ -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(', ')})` +} diff --git a/packages/toolshed/src/core/index.ts b/packages/toolshed/src/core/index.ts index d921cccc3..3934ed378 100644 --- a/packages/toolshed/src/core/index.ts +++ b/packages/toolshed/src/core/index.ts @@ -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'