yesodweb / yesodweb/persistent

Better error message for dealing with bad constructors

Open
#537 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement Newcomer
Dominant language
Haskell
Stars
486
Forks
306
PR merge metrics
No merged PRs in 30d

Description

config/models

Test
   field Text.

Error:

Model.hs:13:7:
    Illegal type constructor or class name: ‘Text.’

and it goes on with a huge dump of TH splices.

In practice, it's unlikely any user will actually face this unless they accidentally typo, but it's good practice to give good error messages.

The fix is as follows:
In persistent, Database.Persist.Quasi, Lines 67-69,

    getCon t =
        case T.breakOnEnd "." t of
            (_, "") -> FTTypeCon Nothing t

should be

    getCon t =
        case T.breakOnEnd "." t of
            (t', "") -> error ("Invalid data constructor - dangling qualifier: " ++ T.unpack t')

Since this is harmless, maybe it can be snuck in a code refactor commit in the future?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the reproducer in config/models and inspect Database.Persist.Quasi around lines 67-69; Model.hs:13:7 shows the current compiler error and TH dump. Done means dangling-qualified constructors produce the specified invalid-data-constructor message instead of the existing error output.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
databases
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.