Skip to content
This repository was archived by the owner on Oct 9, 2023. It is now read-only.

Conversation

@alexjpwalker
Copy link
Member

What is the goal of this PR?

Previously, the TypeDBClientError constructor was a bit of a mess, meaning that under certain scenarios, the user was interested in error.message; in other scenarios, error.errorMessage, and this was pretty ridiculous because the two names are basically synonymous.

So we renamed errorMessage to messageTemplate, and ensured that the content of error.message is always a human-readable string.

What are the changes implemented in this PR?

  • Rename TypeDBClientError.errorMessage to messageTemplate to reduce likelihood of confusing it with message
  • Ensure content of error.message is always a human-readable string

@alexjpwalker alexjpwalker marked this pull request as ready for review July 21, 2021 14:03
get errorMessage(): ErrorMessage {
return this._errorMessage;
get messageTemplate(): ErrorMessage {
return this._messageTemplate;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The trouble with the name errorMessage is that TypeDBClientError extends Error which has a property named message.

message and errorMessage are synonymous in this context; messageTemplate, less so.

else if ("code" in error) {
if ([Status.UNAVAILABLE, Status.UNKNOWN, Status.CANCELLED].includes(error.code) || error.message.includes("Received RST_STREAM")) {
this._errorMessage = UNABLE_TO_CONNECT;
super(UNABLE_TO_CONNECT.message());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So previously we had this confusing situation where, if you had a connection failure, error.errorMessage was "Failed to connect to TypeDB server" and error.message was "14 UNAVAILABLE: No connection established".

And if you had a query error, error.errorMessage was null and error.message was "[QRY04] Query Error: ..."

This resulted in awful application code where we would check the errorMessage, and if there wasn't one, check the message, and so on.

Now, message is a built-in property of Error and it is strongly recommended to not set the property manually, because it is used by various other properties such as toString and stack. Instead, the correct JS way is to call super, passing in the message as a parameter.

But, super must be the first assignment statement in a constructor.

So we've ended up with this construction: we do all the checks, and then call super with the appropriate message and then set _messageTemplate if applicable.

As a result, the user now only ever needs to worry about message, except in special cases like detecting connection failures.

}
super(CLUSTER_REPLICA_NOT_PRIMARY.message());
this._messageTemplate = CLUSTER_REPLICA_NOT_PRIMARY;
} else if (error.code === Status.INTERNAL) super(error.details)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here we need error.details as opposed to error.toString, because otherwise we get: "Error: 13 INTERNAL: [CLI01]: Client Error: The transaction has been closed and no further operation is allowed", which is not a very nice message. details is a property of gRPC's ServiceError.

Copy link
Member

@flyingsilverfin flyingsilverfin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! Do you think the title reflects the most important change? Is it the printouts the user of the client sees, or the API/UX of using the TypeDBClientError class?

@alexjpwalker alexjpwalker changed the title Human-readable errors Improve UX of TypeDBClientError Jul 23, 2021
@alexjpwalker alexjpwalker merged commit fb89265 into typedb:master Jul 28, 2021
@alexjpwalker alexjpwalker deleted the better-errors branch July 28, 2021 10:28
dmitrii-ubskii pushed a commit to dmitrii-ubskii/typedb-client-nodejs that referenced this pull request Sep 1, 2023
## What is the goal of this PR?

There was an error in test-deployment-pip caused by old syntax, which we fixed.

## What are the changes implemented in this PR?

Fix error in test-deployment-pip
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants