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

[experimental] [object Object] in error context (websocket failed to connect) #2572

Closed
mcintyre94 opened this issue Apr 26, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@mcintyre94
Copy link
Collaborator

Overview

  • I created an rpcSubscriptions object with a ws:// URL instead of wss:// by mistake
  • When I tried to use it, I got an error thrown
  • When I decode it, it includes "errorEvent": "[object Object]" in the context
  • I'm not sure if we have other cases where we're stringifying objects like this

Steps to reproduce

import { createSolanaRpc, createSolanaRpcSubscriptions } from '@solana/web3.js';
import { createRecentSignatureConfirmationPromiseFactory } from '@solana/transaction-confirmation';

const rpc = createSolanaRpc('https://api.devnet.solana.com');

const rpcSubscriptions = createSolanaRpcSubscriptions(
  'ws://api.devnet.solana.com' // bad url, should be wss://
);

const getRecentSignatureConfirmationPromise =
  createRecentSignatureConfirmationPromiseFactory({
    rpc,
    rpcSubscriptions,
  });

await getRecentSignatureConfirmationPromise({
  signature:
    '4W8HheCp1QGFVXXT3skxpZazjo9ajyFyAFfLSJaLKdmJqjFYJweKU5Agzyf9rRyDBBKGRSdanocmsJrUsamYUotT',
  commitment: 'confirmed',
  abortSignal: new AbortController().signal,
});

Run this, and you get:

Error: Solana error #8190004; Decode this error by running `npx @solana/errors decode -- 8190004 'ZXJyb3JFdmVudD0lNUJvYmplY3QlMjBPYmplY3QlNUQ='`

Run the npx @solana/errors command and you get:

[Decoded] Solana error code #8190004
    - WebSocket failed to connect

[Context]
    {
        "errorEvent": "[object Object]"
    }

Stackblitz repro

Description of bug

In this case the error name is clear enough to know what went wrong. But flagging because we might have other cases where we're putting objects in context and they're not getting stringified to anything useful.

@mcintyre94 mcintyre94 added the bug Something isn't working label Apr 26, 2024
@steveluscher
Copy link
Collaborator

Yeah, this is generally a ‘flaw,’ in big quotation marks. I didn't program in a way to exclude context properties from the serializer. They're not used in the message, so they're harmless, but it creates mental overhead – the kind that made you file this issue.

One reason that I didn't do this is that it would rely on a blocklist that would have to be built into the production error serializer. We'd be forcing people to download that blocklist, and it would include every error in existence, whether you can even hit them or not. We already ship a god awful allowlist of stuff to patch around deficiencies in the RPC, we don't want to do it here too.

@steveluscher
Copy link
Collaborator

I think the best we could do here is something like this:

new SolanaError(CODE, {
  foo: 'bar',
  __hideThisFromTheMessageFormatter: {
    baz: 'bat',
  },
})

…and then have the code merge __hideThisFromTheMessageFormatter into e.context, but otherwise not pass it to the message formatter.

@mcintyre94
Copy link
Collaborator Author

Got it, and I guess we want to pass the object so that if someone catches the error they can access it programatically. I doubt this is worth changing, I'll close it for now.

Copy link
Contributor

github-actions bot commented May 9, 2024

Because there has been no activity on this issue for 7 days since it was closed, it has been automatically locked. Please open a new issue if it requires a follow up.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants