npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@wallet-standard/errors

v0.1.0

Published

This package brings together every error message across all Wallet Standard JavaScript modules.

Downloads

86,678

Readme

@wallet-standard/errors

This package brings together every error message across all Wallet Standard JavaScript modules.

Reading error messages

In development mode

When your bundler sets the environment variable NODE_ENV to development, every error message will be included in the bundle. As such, you will be able to read them in plain language wherever they appear.

[!WARNING] The size of your JavaScript bundle will increase significantly with the inclusion of every error message in development mode. Be sure to build your bundle with NODE_ENV set to production when you go to production.

In production mode

When your bundler sets the environment variable NODE_ENV to anything other than development, error messages will be stripped from the bundle to save space. Only the error code will appear when an error is encountered. Follow the instructions in the error message to convert the error code back to the human-readable error message.

For instance, to recover the error text for the error with code 123:

npx @wallet-standard/errors decode -- 123

Adding a new error

  1. Add a new exported error code constant to src/codes.ts.
  2. Add that new constant to the WalletStandardErrorCode union in src/codes.ts.
  3. If you would like the new error to encapsulate context about the error itself (eg. the public keys for which a transaction is missing signatures) define the shape of that context in src/context.ts.
  4. Add the error's message to src/messages.ts. Any context values that you defined above will be interpolated into the message wherever you write $key, where key is the index of a value in the context (eg. 'Missing a signature for account `$address`').
  5. Publish a new version of @wallet-standard/errors.
  6. Bump the version of @wallet-standard/errors in the package from which the error is thrown.

Removing an error message

  • Don't remove errors.
  • Don't change the meaning of an error message.
  • Don't change or reorder error codes.
  • Don't change or remove members of an error's context.

When an older client throws an error, we want to make sure that they can always decode the error. If you make any of the changes above, old clients will, by definition, not have received your changes. This could make the errors that they throw impossible to decode going forward.

Catching errors

When you catch a WalletStandardError and assert its error code using isWalletStandardError(), TypeScript will refine the error's context to the type associated with that error code. You can use that context to render useful error messages, or to make context-aware decisions that help your application to recover from the error.

import { WALLET_STANDARD_ERROR__ACCOUNT__FEATURE_NOT_SUPPORTED, isWalletStandardError } from '@wallet-standard/errors';

function MyComponent(props) {
    return (
        <ErrorBoundary FallbackComponent={ErrorComponent}>
            <SignMessageForm account={props.account} />
        </ErrorBoundary>
    );
}
function ErrorComponent({ error }) {
    if (
        isWalletStandardError(error, WALLET_STANDARD_ERROR__ACCOUNT__FEATURE_NOT_SUPPORTED) &&
        error.context.featureName === 'solana:signMessage'
    ) {
        return (
            <span>
                The account <AccountLink account={error.account} /> does not support signing messages. Please choose
                another account.
            </span>
        );
    } else if (error && typeof error === 'object' && 'message' in error) {
        return <span>{String(error.message)}</span>;
    } else {
        return <span>Something went wrong</span>;
    }
}