-
Notifications
You must be signed in to change notification settings - Fork 12
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
Usage of exceptions/errors? #132
Comments
Both cases are not handled by the spec. Also in JS it's not very common to make custom error classes. And |
I think this is important for all methods. For instance, if |
I'd rather prefer clear exceptions or just errors, but with defined error texts, instead of returning false. In a complex environment, a returned false says nothing about the state of the previous operation. Giving the user a way to gather critical information is important, if you handle invalid data, while parsing for instance. |
As a starting point, i propose the following exceptions: InvalidTermUsageInQuadException
ObjectNotMutableException
UndefinedPropertyException
|
2 is not idiomatic; 3 not enforceable on regular objects (except for proxies)
|
I think the best we can hope for would be to say that certain methods should throw an Error, maybe even for example a TypeError, if provided an argument that is not a Term, Quad, etc. This is critical for debugging if a variable in a dev's code is not properly initialized and passes |
I disagree. A Debugging is not hard: the equals method will return |
Not for me... I'd expect equality to be symmetric let term = factory.namedNode('a');
let undef;
term.equals(undef); // false
undef.equals(term); // > TypeError: Cannot read property 'equals' of undefined |
Good point about symmetry, but I assume you don't want |
The symmetry is that they both would throw an error, whether or not the return value from the |
I'm against throwing an error. Maybe in TypeScript, but it's not very "JSish". In JS I don't expect any type error. "not null" or "no empty string" etc. is OK, but type checks are so blurry in JS. Think of this case:
|
The bigger point is that we are doing nobody any favors by returning |
Me; I don't have to write a
That would be me. I've just always written We do not have a lot to go in in JavaScript-land though, except for My notion of |
To assume that |
...you might have just finally convinced me 🙂
Actually, Number.isFinite, Number.isInteger, Number.isSafeInteger, Number.isNaN, String.prototype.startsWith and String.prototype.includes (perhaps the most important one for this case) all return |
Good morning, i also would prefer not to throw anything when using @RubenVerborgh wrote:
That's the point. Setting an invalid value for predicate in (1) for me is clearly an invalid state. The program should not ignore that, because it violates the specification. If you accept that, than why care about these statements in the specification?
Case (2) could go either way. Throwing or ignore the change. I would like to rephrase my initial question: In which cases are we reaching an invalid state and can't process with the given input? Thanks for the responses. |
My life as a developer is much easier if the libraries help me catch errors as soon as they occur, rather than having to gradually back up in a debugger from a pathological consequence much later on. An uncaught exception tells me immediately that I invoked a function with bad parameters; I find and fix those bugs so readily I don't really notice them. To Ruben's point of not having to write |
I totally agree with this, the dangers of passing around a value that you believe is a Term or a Quad but is actually not defined are far reaching -- however, there seems to be strong precedent in JavaScript for returning false with class method calls when they are passed an instance of their same class, i.e., |
It appears to me ECMAScript returns false when the method is a question, as opposed to an operation in general. For example, I throw an error for malformed IRIs in constructors, for example—as that's clearly nonsensical. (And this could be implemented as an assertion that can be disabled in production.) For questions like And actually, in my implementation, there's an option to treat protypical values (string, etc) as a Literal. So it's not all that odd to ask my function I'm not sure if we need to treat this in the text though. There might be a legitimate reason to have it one way or the other for different contexts. As long as implementations right now seem to be doing the right thing, which I think includes a preference to throw as early as possible. |
I think this implementation does not conform to #142 and if code relying on it gets a |
Enabling this deeply modifies the built-in prototypes; it's sketchy
behavior to say the least, but it descends from webr3's js3 library and is
intended for environments that want to deeply embed RDF semantics the same
way Node.js has a standard Buffer implementation.
…On Tue, Jan 22, 2019, 09:17 elf Pavlik ***@***.*** wrote:
And actually, in my implementation, there's an option to treat protypical
values (string, etc) as a Literal. So it's not all that odd to ask my
function literal("0","http://www.w3.org/2001/XMLSchema#boolean
").equals(false)—the answer there is true.
I think this implementation does not conform to #142
<#142> and if code
relying on it gets a Literal produced by different data factory it will
get answer false
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#132 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAatDSXwpdPXv0HuWzMrnzR1mFNBTiyhks5vFzmZgaJpZM4YxgOF>
.
|
The specification currently doesn't specific certain errors or exceptions. Is that intended? Would you open to define ones for certain cases?
One would be if someone tries to change an instance of
Term
orQuad
. But perhaps the decision was already made against that (ref #81).Another one, if you use the wrong
Term
subclass in a quad, e.g. predicate = BlankNode.(ref #130)
The text was updated successfully, but these errors were encountered: