Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve error handling for deploy command #1595

Merged
merged 1 commit into from
Feb 28, 2024
Merged
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
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 { 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 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 @@
// @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 @@
// @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 @@
$ 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 Expand Up @@ -434,7 +445,7 @@
}

if (network) {
const identifierName = protocol.getContract()!.identifierName();

Check warning on line 448 in packages/cli/src/commands/deploy.ts

View workflow job for this annotation

GitHub Actions / Lint

Forbidden non-null assertion
await updateSubgraphNetwork(manifest, network, networkFile, identifierName);
}

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.

Loading