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

Allow use of instance variables for custom Error classes in Rails/HelperInstanceVariable #958

Closed
januszm opened this issue Mar 21, 2023 · 2 comments

Comments

@januszm
Copy link

januszm commented Mar 21, 2023

Is your feature request related to a problem? Please describe.

When I use a custom Error class in a helper method using a variable, it gets flagged by Rails/HelperInstanceVariable.

Describe the solution you'd like

I'd like Rails/HelperInstanceVariable to accept assignment to instance variables for use with a custom Error class:

module SomeHelper
  class InvalidSomethingError < StandardError
    attr_reader :foo

    def initialize(messsage = nil, foo: nil)
      super(message)
      @foo = foo
    end

    def message
      klass = foo.is_a?(Class) ? foo : foo.class
      "#{klass} is not supported!"
    end
  end

  # def helper methods that use InvalidSomethingError
end

Similar to: #311

@koic
Copy link
Member

koic commented Mar 21, 2023

I'm wondering if it makes sense for exception classes to be placed in helpers where view helper is placed. Probably it will be placed in a place such as models or controllers.

@koic koic closed this as not planned Won't fix, can't repro, duplicate, stale Mar 21, 2023
@januszm
Copy link
Author

januszm commented Mar 21, 2023

Depends, custom error classes are often, defined where they belong, eg in a service class or other that is not a model or controller. I have a use case where I only need this error inside helpers but I won't insist 😉

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

No branches or pull requests

2 participants