Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "undefined method `<'" error message #774

Merged
merged 2 commits into from
Apr 5, 2020
Merged

Fix "undefined method `<'" error message #774

merged 2 commits into from
Apr 5, 2020

Conversation

erikkessler1
Copy link
Contributor

Problem

I have some files in the "models" directory that are not true a Class. For example, a dry-types sum type:

# app/models/foo.rb
Foo = Types::String | Types::Integer

This results in the following line when I annotate.

Unable to annotate app/models/foo.rb: undefined method `<' for #<Dry::Struct::Sum:0x00007ff2dd262988>

Not a blocking issue but somewhat annoying nonetheless.

Solution

When annotating a file, check that the file's object is a Class to ensure it has the interface we expect.

This checks that the object we are trying to annotate is a Class to
ensure it has the interface we expect.
Copy link
Collaborator

@drwl drwl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contributing! Looks good to me.

@drwl drwl merged commit d9392d9 into ctran:develop Apr 5, 2020
vfonic pushed a commit to vfonic/annotate_models that referenced this pull request May 8, 2020
## Problem

I have some files in the "models" directory that are not true a `Class`. For example, a [`dry-types`](https://dry-rb.org/gems/dry-types/1.2/sum/) sum type:

```ruby
# app/models/foo.rb
Foo = Types::String | Types::Integer
```

This results in the following line when I annotate.

```
Unable to annotate app/models/foo.rb: undefined method `<' for #<Dry::Struct::Sum:0x00007ff2dd262988>
```

Not a blocking issue but somewhat annoying nonetheless.

## Solution

When annotating a file, check that the file's object is a `Class` to ensure it has the interface we expect.
ctran pushed a commit that referenced this pull request Jun 14, 2021
This commit partially reverts #801, which by declaring conditional return
has turned `get_loaded_model_by_path` to a less safe method that can
return nil when its the condition is not met.

Apparently the very same condition has been brought to `annotate_model_file`
by #774, which seems to cover the "bug" insisted in #801 as well.

On the other hand #801 has brought an inconvenient behaviour as well:
whenever a non-activerecord model file is found, `get_loaded_model_by_path`
returns nil, which leads to raising `BadModelFileError` and ends up
printing a bunch of "Unable to annotate ..." messages.

Now it seems tests added by #801 are running right and I do not find
a problem restoring the previous behaviour and turn it nil-safe again.
ocarta-l pushed a commit to ocarta-l/annotate_models that referenced this pull request Jun 18, 2021
This commit partially reverts ctran#801, which by declaring conditional return
has turned `get_loaded_model_by_path` to a less safe method that can
return nil when its the condition is not met.

Apparently the very same condition has been brought to `annotate_model_file`
by ctran#774, which seems to cover the "bug" insisted in ctran#801 as well.

On the other hand ctran#801 has brought an inconvenient behaviour as well:
whenever a non-activerecord model file is found, `get_loaded_model_by_path`
returns nil, which leads to raising `BadModelFileError` and ends up
printing a bunch of "Unable to annotate ..." messages.

Now it seems tests added by ctran#801 are running right and I do not find
a problem restoring the previous behaviour and turn it nil-safe again.
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.

2 participants