Skip to content

Commit decff14

Browse files
authored
fix: improve error handling for deploy command (#1595)
1 parent f46be9c commit decff14

File tree

3 files changed

+33
-17
lines changed

3 files changed

+33
-17
lines changed

.changeset/thick-tools-jam.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphprotocol/graph-cli': patch
3+
---
4+
5+
improve error handling for `graph deploy`

packages/cli/src/commands/deploy.ts

+17-6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { updateSubgraphNetwork } from '../command-helpers/network';
1212
import { chooseNodeUrl, getHostedServiceSubgraphId } from '../command-helpers/node';
1313
import { assertGraphTsVersion, assertManifestApiVersion } from '../command-helpers/version';
1414
import { GRAPH_CLI_SHARED_HEADERS } from '../constants';
15+
import debugFactory from '../debug';
1516
import Protocol from '../protocols';
1617

1718
const headersFlag = Flags.custom<Record<string, string>>({
@@ -23,6 +24,8 @@ const headersFlag = Flags.custom<Record<string, string>>({
2324

2425
const productOptions = ['subgraph-studio', 'hosted-service'];
2526

27+
const deployDebugger = debugFactory('graph-cli:deploy');
28+
2629
export default class DeployCommand extends Command {
2730
static description = 'Deploys a subgraph to a Graph node.';
2831

@@ -205,17 +208,21 @@ export default class DeployCommand extends Command {
205208
// @ts-expect-error TODO: why are the arguments not typed?
206209
res,
207210
) => {
211+
deployDebugger('requestError: %O', requestError);
212+
deployDebugger('jsonRpcError: %O', jsonRpcError);
208213
if (jsonRpcError) {
209-
let errorMessage = `Failed to deploy to Graph node ${requestUrl}: ${jsonRpcError.message}`;
214+
const message = jsonRpcError?.message || jsonRpcError?.code?.toString();
215+
deployDebugger('message: %O', message);
216+
let errorMessage = `Failed to deploy to Graph node ${requestUrl}: ${message}`;
210217

211218
// Provide helpful advice when the subgraph has not been created yet
212-
if (jsonRpcError.message.match(/subgraph name not found/)) {
219+
if (message?.match(/subgraph name not found/)) {
213220
errorMessage += `
214221
Make sure to create the subgraph first by running the following command:
215222
$ graph create --node ${node} ${subgraphName}`;
216223
}
217224

218-
if (jsonRpcError.message.match(/auth failure/)) {
225+
if (message?.match(/auth failure/)) {
219226
errorMessage += '\nYou may need to authenticate first.';
220227
}
221228

@@ -336,11 +343,15 @@ export default class DeployCommand extends Command {
336343
// @ts-expect-error TODO: why are the arguments not typed?
337344
res,
338345
) => {
346+
deployDebugger('requestError: %O', requestError);
347+
deployDebugger('jsonRpcError: %O', jsonRpcError);
339348
if (jsonRpcError) {
340-
let errorMessage = `Failed to deploy to Graph node ${requestUrl}: ${jsonRpcError.message}`;
349+
const message = jsonRpcError?.message || jsonRpcError?.code?.toString();
350+
deployDebugger('message: %O', message);
351+
let errorMessage = `Failed to deploy to Graph node ${requestUrl}: ${message}`;
341352

342353
// Provide helpful advice when the subgraph has not been created yet
343-
if (jsonRpcError.message.match(/subgraph name not found/)) {
354+
if (message?.match(/subgraph name not found/)) {
344355
if (isHostedService) {
345356
errorMessage +=
346357
'\nYou may need to create it at https://thegraph.com/explorer/dashboard.';
@@ -350,7 +361,7 @@ export default class DeployCommand extends Command {
350361
$ graph create --node ${node} ${subgraphName}`;
351362
}
352363
}
353-
if (jsonRpcError.message.match(/auth failure/)) {
364+
if (message?.match(/auth failure/)) {
354365
errorMessage += '\nYou may need to authenticate first.';
355366
}
356367
spinner.fail(errorMessage);

pnpm-lock.yaml

+11-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)