Skip to content

Commit 05376ed

Browse files
committed
Don't use Exception, use StandardError
It's bad Ruby practice to have Error classes inherit directly from Exception, or to raise instances of Exception itself. It is highly recommended that any custom error classes inherit instead from StandardError. StandardError is also the go-to exception class for when you need to raise an error without a custom class. Signed-off-by: David Celis <[email protected]>
1 parent c0f38a1 commit 05376ed

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

lib/onelogin/ruby-saml/logoutresponse.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def valid_saml?(soft = true)
105105
if soft
106106
@schema.validate(@xml).map{ return false }
107107
else
108-
@schema.validate(@xml).map{ |error| raise(Exception.new("#{error.message}\n\n#{@xml.to_s}")) }
108+
@schema.validate(@xml).map{ |error| raise(StandardError.new("#{error.message}\n\n#{@xml.to_s}")) }
109109
end
110110
end
111111

@@ -151,4 +151,4 @@ def validation_error(message)
151151
end
152152
end
153153
end
154-
end
154+
end

lib/onelogin/ruby-saml/validation_error.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module Onelogin
22
module Saml
3-
class ValidationError < Exception
3+
class ValidationError < StandardError
44
end
55
end
66
end

test/logoutresponse_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class RubySamlTest < Test::Unit::TestCase
102102
should "raise error for invalid xml" do
103103
logoutresponse = Onelogin::Saml::Logoutresponse.new(invalid_xml_response, settings)
104104

105-
assert_raises(Exception) { logoutresponse.validate! }
105+
assert_raises(StandardError) { logoutresponse.validate! }
106106
end
107107
end
108108

0 commit comments

Comments
 (0)