Feature #5866

ValidationError

Added by Thomas Sawyer over 2 years ago. Updated over 1 year ago.

[ruby-core:41987]
Status:Feedback
Priority:Normal
Assignee:-
Category:-
Target version:next minor

Description

I've come across this from time to time, where some piece of complex data, often (but not always) loaded from a file, doesn't conform to some set of validation requirements. I've never been quite sure what type of error to throw if the data doesn't conform. It's not exactly an ArgumentError, it's more complex then that and not necessarily coming in via method arguments, nor is it exactly a TypeError since it's not necessarily anything to do with a specific class. So I find myself falling back to Runtime error and rolling my own, but thinking it would be nice if there were a general purpose ValidationError to raise or subclass in these cases.

History

#1 Updated by Anonymous over 2 years ago

On 01/08/2012 04:57 AM, Thomas Sawyer wrote:

I've come across this from time to time, where some piece of complex
data, often (but not always) loaded from a file, doesn't conform to
some set of validation requirements. I've never been quite sure what
type of error to throw if the data doesn't conform. It's not exactly
an ArgumentError, it's more complex then that and not necessarily
coming in via method arguments, nor is it exactly a TypeError since
it's not necessarily anything to do with a specific class. So I find
myself falling back to Runtime error and rolling my own, but thinking
it would be nice if there were a general purpose ValidationError to
raise or subclass in these cases.

Why not subclass Syntax error, and put the class in a namespace
belonging to your particular validation requirements? This is more or
less what YAML does.

#2 Updated by Nobuyoshi Nakada over 2 years ago

  • Status changed from Open to Feedback

It sounds like an application (or library) layer story.
Why does it need to be supported in the language layer?

#3 Updated by Thomas Sawyer over 2 years ago

SyntaxError? I suppose we might assume that's appropriate if YAML is doing it, but ScriptError is not a StandardError, rather it is a ScriptError, which I think means it's supposed to be for RUBY syntax errors only. Am I wrong to think that?

"It sounds like an application (or library) layer story. Why does it need to be supported in the language layer?"

Yes, but it's helpful to base an app/library's errors on a standard superclass that fits. If a type of exception is so very common then I think it makes sense for Ruby to have a standard exception for it. I think validation is a very clear case for that. And an example for it might well be the fore mentioned YAML's use of SyntaxError, where something like ValidationError might, it seems to me, be more appropriate.

#4 Updated by Thomas Sawyer over 2 years ago

Oops, that should read "but SyntaxError is not a StandardError"

#5 Updated by Alex Young over 2 years ago

Maybe:

class InputFormatError < IOError
end

?

--
Alex

On 08/01/12 12:57, Thomas Sawyer wrote:

Issue #5866 has been reported by Thomas Sawyer.


Feature #5866: ValidationError
https://bugs.ruby-lang.org/issues/5866

Author: Thomas Sawyer
Status: Open
Priority: Normal
Assignee:
Category:
Target version: 2.0.0

I've come across this from time to time, where some piece of complex data, often (but not always) loaded from a file, doesn't conform to some set of validation requirements. I've never been quite sure what type of error to throw if the data doesn't conform. It's not exactly an ArgumentError, it's more complex then that and not necessarily coming in via method arguments, nor is it exactly a TypeError since it's not necessarily anything to do with a specific class. So I find myself falling back to Runtime error and rolling my own, but thinking it would be nice if there were a general purpose ValidationError to raise or subclass in these cases.

#6 Updated by Koichi Sasada over 1 year ago

  • Target version changed from 2.0.0 to next minor

I changed target to next minor because no feedback there.

Also available in: Atom PDF