Skip to content

Generated JS client drops custom error messages in production (NODE_ENV guard) #154

@Vishwa9011

Description

@Vishwa9011

Summary

The JS client generated by @codama/renderers-js only includes program error messages when NODE_ENV !== 'production'. In production builds (e.g., Next.js), getErrorMessage() always returns the placeholder and the app shows the “npx @solana/errors decode …” hint instead of the program’s custom error message. Shipping the generated folder does not help because the guard is evaluated at build time.

Problem to solve

Steps to Reproduce

  1. Create an Anchor program with custom errors (e.g., code 6000, message “Factory paused.”).
  2. Run codama with @codama/renderers-js to generate the JS client.
  3. Use the generated getErrorMessage() (or similar helper) in a Next.js app to map custom errors.
  4. Run in dev mode, trigger custom error -> message appears.
  5. Build and run production, trigger the same error.

Actual Behavior

  • In production, getErrorMessage(code) returns:
    "Error message not available in production bundles."
  • The SolanaError message includes:
    Solana error #<code>; Decode this error by running npx @solana/errors decode -- <code> ...

Expected Behavior

  • There should be a supported way to include custom program error messages in production, or a documented recommended approach for accurate error decoding in production (client or server).

Generated Output (snippet)
The generated file uses a production guard:

let myProgramErrorMessages: Record<MyProgramError, string> | undefined;
if (process.env.NODE_ENV !== 'production') {
  myProgramErrorMessages = { ... };
}

export function getMyProgramErrorMessage(code: MyProgramError): string {
  if (process.env.NODE_ENV !== 'production') {
    return myProgramErrorMessages![code];
  }
  return 'Error message not available in production bundles.';
}

### Proposed solution

May be error messages should be in production too.

### Alternatives considered

Environment

codama: 1.5.0
@codama/renderers-js: 1.5.5
@solana/kit: 5.4.0
Next.js: 16.0.10
Node: 20+
Questions / Request

Is there an official flag or supported option to always include error messages in production builds?
If not, what is the recommended pattern to handle custom program error decoding accurately in production?
Would you consider adding a renderer option (e.g., alwaysIncludeErrorMessages: true) or exporting a separate error map for production use?

### Additional context

_No response_

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions