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

feat: show more informative rpc error #216

Merged
merged 1 commit into from
Dec 20, 2023
Merged

Conversation

samsiegart
Copy link
Collaborator

@samsiegart samsiegart commented Dec 19, 2023

refs Agoric/agoric-sdk#8505
fixes Agoric/ui-kit#57

This uses the new @agoric/rpc and @agoric/web-components to make some improvements to error handling as a precursor to the node selector. The new package versions have a few improvements:

  • No longer use the batch vstorage API which is deprecated, instead poll each vstorage path from the API server separately
  • No longer have a separate onError handler for each vstorage path. For missing data, it now just yields an empty value, and server errors are surfaced to the single onError handler of the chainStorageWatcher
  • Add an error handler to wallet connection component for RPC/API errors which indicates which endpoint is failing (RPC or API)
  • Automatically retry all queries before surfacing onError (in both wallet connection component and chainStorageWatcher)
  • Fix some bugs in the wallet connection component around offer and smart-wallet-provision status updates

With all these changes, the dapp can now more gracefully and confidently handle server errors and show a more informative dialog instead of crashing with an unhelpful error message on the screen. In the future we can prompt the user to select a different node in this case, but for now just the dialog is being added.

Screenshot

image

Copy link

github-actions bot commented Dec 19, 2023

Network:
Commit: b01aa28
Ref: refs/heads/main
IPFS v1 hash: bafybeify656qb5s6lkwsqpych2k7bwtgpp3i7uqv3rhy33q5usa3ayzxfy
CF - DWeb - 4EVERLAND

@@ -155,6 +162,9 @@ const watchUserVaults = () => {
[Kind.Data, path],
value => {
console.debug('got update', subscriber, value);
if (!value) {
return;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We might receive the update to offerIdsToPublicSubscribers from the user's wallet and start watching the vault before the vault data is actually published to vstorage, so we don't want to error out in that case. Just wait for the data to show up assuming it will eventually. I'm not sure how else to handle it, but worst case if the contract had a bug the vault would just perpetually show a loading state.

setError(e);
setChainConnectionError(
new Error(
`Error fetching network config from ${netConfig.url}` +
Copy link
Contributor

Choose a reason for hiding this comment

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

question:
Why is this using

e instanceof Error ? `: ${e.message}` : ''

while just above it's only

e.message

Is it because we know makeAgoricChainStorageWatcher is giving us an instance of Error but we don't know if the catch is?

Copy link
Member

Choose a reason for hiding this comment

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

There's probably value in introducing a helper for use in both places; something like

const makeError = (msg, { cause } = {}) => {
  const longMsg = !cause
    ? msg
    : `${msg}: ${cause instanceof Error ? cause.message : cause}`;
  return Error(longMsg, { cause });
};

Copy link
Member

@gibson042 gibson042 left a comment

Choose a reason for hiding this comment

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

I'm not 100% clear on the React details, but close enough to feel confident in this review. No blocking issues spotted.

setError(e);
setChainConnectionError(
new Error(
`Error fetching network config from ${netConfig.url}` +
Copy link
Member

Choose a reason for hiding this comment

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

There's probably value in introducing a helper for use in both places; something like

const makeError = (msg, { cause } = {}) => {
  const longMsg = !cause
    ? msg
    : `${msg}: ${cause instanceof Error ? cause.message : cause}`;
  return Error(longMsg, { cause });
};

)}
{rpcNode && (
<p>
RPC Endpoint: <span className="text-blue-500">{rpcNode}</span>
Copy link
Member

Choose a reason for hiding this comment

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

Nit: a blue URL looks like a hyperlink. It might be best to choose a different color and/or replace the <span> with <input readonly>.

</p>
)}
<p>
Error:{' '}
Copy link
Member

@gibson042 gibson042 Dec 20, 2023

Choose a reason for hiding this comment

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

We can avoid repeating "error".

Suggested change
Error:{' '}
Detail:{' '}

Also, is text:{' '} more idiomatic than {'text: '}?

const body = (
<div className="mt-2 p-1 max-h-96 overflow-y-auto">
<p className="mb-2">
There was an issue connecting to the chain - likely due to RPC node
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
There was an issue connecting to the chain - likely due to RPC node
There was a problem connecting to the chain - likely due to RPC node

);

return (
<ActionsDialog
Copy link
Member

Choose a reason for hiding this comment

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

Not requesting a change, but I guess this is no longer an actions dialog.

appStore.setState({
watchVbankError: 'Error loading asset display info',
watchVbankError: `${path} returned undefined`,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
watchVbankError: `${path} returned undefined`,
watchVbankError: `No value at ${path}`,

(better covers non-undefined falsy values in correspondence with the actual test)

appStore
.getState()
.setChainConnectionError(
new Error(
Copy link
Member

Choose a reason for hiding this comment

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

Another good candidate for the suggested helper.

@ivanlei ivanlei merged commit b01aa28 into main Dec 20, 2023
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants