Skip to content

Commit

Permalink
fix: improve error handling for deploy command (#1595)
Browse files Browse the repository at this point in the history
  • Loading branch information
saihaj authored Feb 28, 2024
1 parent f46be9c commit decff14
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
5 changes: 5 additions & 0 deletions .changeset/thick-tools-jam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphprotocol/graph-cli': patch
---

improve error handling for `graph deploy`
23 changes: 17 additions & 6 deletions packages/cli/src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Record<string, string>>({
Expand All @@ -23,6 +24,8 @@ const headersFlag = Flags.custom<Record<string, string>>({

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.';

Expand Down Expand Up @@ -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.';
}

Expand Down Expand Up @@ -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.';
Expand All @@ -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);
Expand Down
22 changes: 11 additions & 11 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit decff14

Please sign in to comment.