diff --git a/.changeset/thick-tools-jam.md b/.changeset/thick-tools-jam.md new file mode 100644 index 00000000..50d6b95c --- /dev/null +++ b/.changeset/thick-tools-jam.md @@ -0,0 +1,5 @@ +--- +'@graphprotocol/graph-cli': patch +--- + +improve error handling for `graph deploy` diff --git a/packages/cli/src/commands/deploy.ts b/packages/cli/src/commands/deploy.ts index 5122750a..c538eecc 100644 --- a/packages/cli/src/commands/deploy.ts +++ b/packages/cli/src/commands/deploy.ts @@ -12,6 +12,7 @@ import { updateSubgraphNetwork } from '../command-helpers/network'; import { chooseNodeUrl, getHostedServiceSubgraphId } from '../command-helpers/node'; import { assertGraphTsVersion, assertManifestApiVersion } from '../command-helpers/version'; import { GRAPH_CLI_SHARED_HEADERS } from '../constants'; +import debugFactory from '../debug'; import Protocol from '../protocols'; const headersFlag = Flags.custom>({ @@ -23,6 +24,8 @@ const headersFlag = Flags.custom>({ const productOptions = ['subgraph-studio', 'hosted-service']; +const deployDebugger = debugFactory('graph-cli:deploy'); + export default class DeployCommand extends Command { static description = 'Deploys a subgraph to a Graph node.'; @@ -205,17 +208,21 @@ export default class DeployCommand extends Command { // @ts-expect-error TODO: why are the arguments not typed? res, ) => { + deployDebugger('requestError: %O', requestError); + deployDebugger('jsonRpcError: %O', jsonRpcError); if (jsonRpcError) { - let errorMessage = `Failed to deploy to Graph node ${requestUrl}: ${jsonRpcError.message}`; + const message = jsonRpcError?.message || jsonRpcError?.code?.toString(); + deployDebugger('message: %O', message); + let errorMessage = `Failed to deploy to Graph node ${requestUrl}: ${message}`; // Provide helpful advice when the subgraph has not been created yet - if (jsonRpcError.message.match(/subgraph name not found/)) { + if (message?.match(/subgraph name not found/)) { errorMessage += ` Make sure to create the subgraph first by running the following command: $ graph create --node ${node} ${subgraphName}`; } - if (jsonRpcError.message.match(/auth failure/)) { + if (message?.match(/auth failure/)) { errorMessage += '\nYou may need to authenticate first.'; } @@ -336,11 +343,15 @@ export default class DeployCommand extends Command { // @ts-expect-error TODO: why are the arguments not typed? res, ) => { + deployDebugger('requestError: %O', requestError); + deployDebugger('jsonRpcError: %O', jsonRpcError); if (jsonRpcError) { - let errorMessage = `Failed to deploy to Graph node ${requestUrl}: ${jsonRpcError.message}`; + const message = jsonRpcError?.message || jsonRpcError?.code?.toString(); + deployDebugger('message: %O', message); + let errorMessage = `Failed to deploy to Graph node ${requestUrl}: ${message}`; // Provide helpful advice when the subgraph has not been created yet - if (jsonRpcError.message.match(/subgraph name not found/)) { + if (message?.match(/subgraph name not found/)) { if (isHostedService) { errorMessage += '\nYou may need to create it at https://thegraph.com/explorer/dashboard.'; @@ -350,7 +361,7 @@ export default class DeployCommand extends Command { $ graph create --node ${node} ${subgraphName}`; } } - if (jsonRpcError.message.match(/auth failure/)) { + if (message?.match(/auth failure/)) { errorMessage += '\nYou may need to authenticate first.'; } spinner.fail(errorMessage); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f3c7be19..d882aecf 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -47,7 +47,7 @@ importers: examples/arweave-blocks-transactions: devDependencies: '@graphprotocol/graph-cli': - specifier: 0.68.0 + specifier: 0.68.3 version: link:../../packages/cli '@graphprotocol/graph-ts': specifier: 0.33.0 @@ -63,7 +63,7 @@ importers: version: 6.26.0 devDependencies: '@graphprotocol/graph-cli': - specifier: 0.68.0 + specifier: 0.68.3 version: link:../../packages/cli '@graphprotocol/graph-ts': specifier: 0.33.0 @@ -82,7 +82,7 @@ importers: version: 6.26.0 devDependencies: '@graphprotocol/graph-cli': - specifier: 0.68.0 + specifier: 0.68.3 version: link:../../packages/cli '@graphprotocol/graph-ts': specifier: 0.33.0 @@ -101,7 +101,7 @@ importers: version: 6.26.0 devDependencies: '@graphprotocol/graph-cli': - specifier: 0.68.0 + specifier: 0.68.3 version: link:../../packages/cli '@graphprotocol/graph-ts': specifier: 0.33.0 @@ -120,7 +120,7 @@ importers: version: 6.26.0 devDependencies: '@graphprotocol/graph-cli': - specifier: 0.68.0 + specifier: 0.68.3 version: link:../../packages/cli '@graphprotocol/graph-ts': specifier: 0.33.0 @@ -172,7 +172,7 @@ importers: version: 5.0.4 devDependencies: '@graphprotocol/graph-cli': - specifier: 0.68.0 + specifier: 0.68.3 version: link:../../packages/cli '@graphprotocol/graph-ts': specifier: 0.33.0 @@ -190,7 +190,7 @@ importers: examples/ethereum-gravatar: devDependencies: '@graphprotocol/graph-cli': - specifier: 0.68.0 + specifier: 0.68.3 version: link:../../packages/cli '@graphprotocol/graph-ts': specifier: 0.33.0 @@ -211,7 +211,7 @@ importers: examples/matic-lens-protocol-posts-subgraph: dependencies: '@graphprotocol/graph-cli': - specifier: 0.68.0 + specifier: 0.68.3 version: link:../../packages/cli '@graphprotocol/graph-ts': specifier: 0.33.0 @@ -224,7 +224,7 @@ importers: examples/near-blocks: devDependencies: '@graphprotocol/graph-cli': - specifier: 0.68.0 + specifier: 0.68.3 version: link:../../packages/cli '@graphprotocol/graph-ts': specifier: 0.33.0 @@ -233,7 +233,7 @@ importers: examples/near-receipts: devDependencies: '@graphprotocol/graph-cli': - specifier: 0.68.0 + specifier: 0.68.3 version: link:../../packages/cli '@graphprotocol/graph-ts': specifier: 0.33.0 @@ -242,7 +242,7 @@ importers: examples/substreams-powered-subgraph: devDependencies: '@graphprotocol/graph-cli': - specifier: 0.68.0 + specifier: 0.68.3 version: link:../../packages/cli packages/cli: