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

Use Better Error Codes For GraphQL Client Errors #2208

Closed
Torres-ssf opened this issue Apr 30, 2024 · 5 comments
Closed

Use Better Error Codes For GraphQL Client Errors #2208

Torres-ssf opened this issue Apr 30, 2024 · 5 comments
Labels
chore Issue is a chore

Comments

@Torres-ssf
Copy link
Contributor

Torres-ssf commented Apr 30, 2024

We need to improve the error codes used when a GraphQL query/mutation/subscription throws an error from the client. This should be done on:

1 - FuelGraphqlSubscriber

2 - Provider.createOperations

This involves analyzing the errors array returned from the graphQL response. An error entry looks similar to this:

  {
    message: 'not enough coins to fit the target',
    locations: [ { line: 2, column: 3 } ],
    path: [ 'coinsToSpend' ]
  }

In this case, we can identify that the error was caused by the query coinsToSpend, and the error message is not enough coins to fit the target.

When implementing this error handling, is essential to identify what was the path ( query/mutation/subscription ) and use a proper FuelError code

Related to this comment

@Torres-ssf Torres-ssf added the chore Issue is a chore label Apr 30, 2024
@Torres-ssf Torres-ssf changed the title Use Better Error Codes For GraphQL Queries / Mutations / Subscriptions Use Better Error Codes For GraphQL Client Errors Apr 30, 2024
@arboleya
Copy link
Member

arboleya commented Apr 30, 2024

The scope of this issue seems a bit open.

What do you think one should do here exactly?

  • Go through all the errors and format them?
  • Which are the errors? How should they be formatted?

This sort of thing.

@Torres-ssf
Copy link
Contributor Author

Torres-ssf commented Apr 30, 2024

@arboleya I believe we just need to use more specific error codes.

For instance, if we validate that the used path was the mutation submit or even the subscription submitAndAwait,

{
  message: 'error message here',
  locations: [ { line: 2, column: 3 } ],
  path: [ 'submit' ] // or ['submitAndAwait']
}

Then we can use a more appropriate error code, like: TRANSACTION_FAILED, because we know for sure that these 2 are used only when submitting a transaction.

throw new FuelError(
  FuelError.CODES.TRANSACTION_FAILED,
  graphQlResponse.errors[0].err.message)
);

We do not need to treat messages, since we can use the same ones thrown by the client.

Perhaps we should start using better error codes only for transaction submission failure. If we validate that the extracted path is not related to transaction submission, we can use the generic error code INVALID_REQUEST

@arboleya arboleya modified the milestones: 1.0 caterpillar, 0.x post-launch Jun 10, 2024
@arboleya arboleya added the p0 label Jun 12, 2024
@arboleya arboleya added p1 and removed p0 labels Jul 19, 2024
@arboleya arboleya removed this from the 0.x post-launch milestone Jul 19, 2024
@arboleya arboleya added p2 and removed p1 labels Jul 19, 2024
@petertonysmith94
Copy link
Contributor

Is this related to or the same as?

@petertonysmith94
Copy link
Contributor

Going to unassign myself from this for now.

@petertonysmith94 petertonysmith94 removed their assignment Sep 9, 2024
@Torres-ssf
Copy link
Contributor Author

Closing this in favor of #2467

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Issue is a chore
Projects
None yet
Development

No branches or pull requests

3 participants