From 9584b0103e21881fd6c8a270d33fbba8c23015f5 Mon Sep 17 00:00:00 2001 From: Chris Ashton Date: Thu, 10 Jun 2021 09:24:11 +0100 Subject: [PATCH] Clarify that you can raise exceptions without arguments Whilst `MyCustomError.new` violates this Rubocop rule, the documentation implies the only way of fixing it is to pass an argument representing the exception message, whereas actually if your custom exception has a default message, it's quite possible you just want to use the default message. This can be achieved without violating this Rubocop rule, by omitting the call to `.new`. --- lib/rubocop/cop/style/raise_args.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/rubocop/cop/style/raise_args.rb b/lib/rubocop/cop/style/raise_args.rb index 3440346a1d8..4f5b35d80a7 100644 --- a/lib/rubocop/cop/style/raise_args.rb +++ b/lib/rubocop/cop/style/raise_args.rb @@ -23,6 +23,7 @@ module Style # # good # raise StandardError, 'message' # fail 'message' + # raise MyCustomError # raise MyCustomError.new(arg1, arg2, arg3) # raise MyKwArgError.new(key1: val1, key2: val2) # @@ -37,6 +38,7 @@ module Style # # # good # raise StandardError.new('message') + # raise MyCustomError # raise MyCustomError.new(arg1, arg2, arg3) # fail 'message' class RaiseArgs < Base