luckyframework / luckyframework/avram

Stack overflow (e.g., infinite or very deep recursion)

Open
#170 5 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

Ok, this one may just be with how I set things up, and we may not even be able to fix this, but just in case....

With rails, it was pretty common for us to define scopes based on certain queries with default values like this:

```ruby
scope :featured, -> { where(featured: true) }
```

porting this over to Avram, I did this:

```crystal
class Movie < BaseModel
table do
column featured : Bool
end
end

class MovieQuery < BaseQuery
def featured
featured(true)
end
end
```

Then calling `MovieQuery.new.featured` led to this error:

```text
Stack overflow (e.g., infinite or very deep recursion)
[0x10db378cb] *CallStack::print_backtrace:Int32 +107
[0x10db08435] __crystal_sigfault_handler +181
[0x7fff601d3b5d] _sigtramp +29
[0x10dc7c905] *MyApp::MovieQuery@MyApp::Movie::BaseQuery#featured:NoReturn +5
[0x10dc7c8fe] *MyApp::MovieQuery#featured:NoReturn +14
[0x10dc7c909] *MyApp::MovieQuery@MyApp::Movie::BaseQuery#featured:NoReturn +9
.... about 5000 lines later
[0x10db11b55] ~procProc(Nil)@spec/my_app/movie_spec.cr:4 +69
[0x10db12415] *it:(Array(Spec::Result)+ | Nil) +645
[0x10db11b02] ~procProc(Nil)@spec/my_app/movie_spec.cr:3 +114
[0x10dbbe4be] *Spec::RootContext::describe:Spec::Context+ +302
[0x10db128c9] *describe:Spec::Context+ +9
[0x10daf263d] __crystal_main +16989
[0x10dc9b7d9] *Crystal::main_user_code:Nil +9
[0x10dc9b748] *Crystal::main:Int32 +40
[0x10dafd9c9] main +9
```

Maybe we can catch if any methods of the same name are defined and then raise a compile time error like "Yo, you bout to blow stuff up...." 😆

Contributor guide

Open the contributing guide

Research direction

Reproduce the failure from MovieQuery#featured using the example in spec/my_app/movie_spec.cr, then trace the interaction between that method and BaseQuery#featured in the stack trace. Determine whether the query API can identify this same-name recursion and establish whether done means preventing the overflow or reporting a clear compile-time error.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.