luckyframework / luckyframework/avram

BaseModel class abstract error

Open
#183 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

improve error experience
Dominant language
Crystal
Stars
183
Forks
67
PR merge metrics
No merged PRs in 30d

Description

If you create your own BaseModel, but forget to make it `abstract`, you can end up with an error like this:

```crystal
class MyBaseModel < Avram::Model
macro default_columns
primary_key id : Int16
timestamps
end
end
```

```
Error in lib/avram/src/avram/model.cr:16: abstract `def Avram::Model#id()` must be implemented by Primetime::PrimetimeBaseModel

abstract def id
^~
```

The error is correct, but it doesn't make sense on why you're getting it since `primary_key id` does define a `id` method. To fix this, the `MyBaseModel` just needs to be `abstract`.

```crystal
abstract class MyBaseModel < Avram::Model
```

I'm not sure how we can fix this, but a better error message would be nice here.

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

Start by reproducing the MyBaseModel example and inspect lib/avram/src/avram/model.cr around the abstract id declaration. Trace why primary_key id is not reflected in the compiler diagnostic when the model is not abstract. Done means the error clearly explains the required abstract declaration or otherwise gives actionable guidance.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.