Skip to content

Conversation

@CharlonTank
Copy link
Contributor

Problem

When users try to use an opaque type with a custom Wire3 encoder (like BiSeqDict) in their BackendModel or FrontendModel, they get a cryptic error message:

-- TOO MANY ARGS
The `w3_encode_BiSeqDict` function expects 1 argument, but it got 3 instead.

This doesn't help users understand what went wrong or how to fix it.

Solution

This PR improves the error message to provide helpful guidance:

-- WIRE3 ENCODER ISSUE -------------------------------------------------

I found an opaque type with a custom Wire3 encoder:

    BiSeqDict

The encoder `encodeBiSeqDict` exists, but I can't generate the
correct wrapper automatically because the type constructor is not exposed.

You have 3 options:

1. Expose the type constructor (simple but wasteful - sends internal structure)
   
2. Add compiler support (efficient - only sends what's needed)
   Make a PR to lamdera/compiler following the SeqDict pattern
   See: https://github.com/lamdera/compiler/blob/master/extra/Lamdera/Wire3/Encoder.hs#L170
   
3. Remove from BackendModel/FrontendModel (if not needed for Wire3)

Changes

  • Modified extra/Lamdera/Wire3/Helpers.hs to detect when encode<TypeName> exists but w3_encode_<TypeName> doesn't
  • Modified extra/Lamdera/Wire3/Encoder.hs to check for custom encoders in same-module case
  • Shows helpful error message with 3 clear options instead of cryptic "TOO MANY ARGS"

Testing

Tested by temporarily removing BiSeqDict special-casing and compiling a project that uses BiSeqDict in BackendModel - confirmed new error message appears.

Related

This improves the developer experience for anyone working with custom opaque types in Lamdera, and will be particularly useful for the upcoming BiSeqDict, MultiSeqDict, and MultiBiSeqDict types in lamdera/containers.

…oders

Instead of the cryptic "TOO MANY ARGS" error, provide a helpful message that explains:
- The issue: opaque type with custom encoder but compiler can't generate wrapper
- Three solutions: expose constructor, add compiler support, or remove from Wire3 types

This helps users understand what went wrong and how to fix it when they try to use
opaque types like BiSeqDict in their BackendModel/FrontendModel without compiler support.
@CharlonTank CharlonTank force-pushed the improve-wire3-custom-encoder-error-message branch from a1f32fd to 9dedc48 Compare November 8, 2025 02:43
Only show the custom encoder/decoder error for user packages, not core
elm/* or lamdera/* packages like Bytes which have special handling.
@CharlonTank CharlonTank force-pushed the improve-wire3-custom-encoder-error-message branch from 3d37693 to b01dfdf Compare November 8, 2025 02:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant