luckyframework / luckyframework/avram

Confusing error message when enum columns encounter unexpected data

Open
#893 0 comments 0 reactions 0 assignees View on GitHub
improve error experience
Dominant language
Crystal
Stars
183
Forks
67
PR merge metrics
No merged PRs in 30d

Description

If you have an enum column:

```crystal
class Model < BaseModel
enum Status
Unknown = -1
Ok = 0
NotOk = 1
end

table :whatever do
column status_code : Model::Status = Model::Status::Unknown
end
end
```

And you pull data from the database which has `status=2`, you'll get this runtime error:

cast from Avram::Type::FailedCast to Avram::Type::SuccessfulCast(T) failed, at /app/lib/avram/src/avram/type.cr:25:5:25

Which is not at all helpful. What's a better way to raise and inform developers about this data corruption?

Contributor guide

Open the contributing guide

Research direction

Start at lib/avram/src/avram/type.cr around line 25 and reproduce the enum-column case where the database contains status=2. Trace how the failed cast becomes the reported runtime error; done means the unexpected enum data produces a clear error that informs developers about the data corruption.

Written by the indexing model from the issue text.

Assessment

Tech stack
crystal, postgresql
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.