Enhance errors.add linter to check symbol as second argument#9569
Enhance errors.add linter to check symbol as second argument#9569
Conversation
changelog: Internal, Automated Testing, Improve accuracy of error type linter
|
For visibility, copying a relevant comment from #9570 where I think what we'd been linting previously is not really standard usage of the errors API:
|
| _attr, type, options = node.arguments | ||
| return if type && type.type == :sym | ||
| options = type if type && type.type == :hash | ||
| return if options && options.type == :hash && options.keys.map(&:value).include?(:type) |
There was a problem hiding this comment.
My micro-optimizing brain didn't like this because it's wasteful to produce a mapped result for the entire hash when we're only interested to iterate up to the point we find the relevant key, but I couldn't fit that solution into a single line 😄
| return if options && options.type == :hash && options.keys.map(&:value).include?(:type) | |
| return if options && options.type == :hash && options.keys.any? { |key| key.value == :type } |
| return if options && options.type == :hash && options.keys.map(&:value).include?(:type) | |
| return if options && options.type == :hash && options.keys.lazy.map(&:value).include?(:type) |
🛠 Summary of changes
Enhances our
errors.addlinter to allow the expectedtypesymbol to be specified as the second argument of theerrors.addcall.The context for this linter is that we want to have a way to query for errors within logs irrespective of locale, and having a symbol "type" supports this, and it's expected to be logged through the
error_detailsproperty.Example:
identity-idp/spec/services/form_response_spec.rb
Lines 141 to 153 in 99916ca
In fact, due to an issue with
FormResponse, only this form oferrors.addcurrently works as expected. See #9570 for a pull request fixing that behavior.📜 Testing Plan
Build should have no failures.