This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 26903 - Parameter validation errors should return SyntaxError not DataError
Summary: Parameter validation errors should return SyntaxError not DataError
Status: RESOLVED FIXED
Alias: None
Product: Web Cryptography
Classification: Unclassified
Component: Web Cryptography API Document (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal
Target Milestone: ---
Assignee: Mark Watson
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 25741
Blocks:
  Show dependency treegraph
 
Reported: 2014-09-25 17:00 UTC by Mark Watson
Modified: 2014-10-30 23:25 UTC (History)
3 users (show)

See Also:


Attachments

Description Mark Watson 2014-09-25 17:00:14 UTC
SyntaxError: A required parameter was missing or out-of-range
DataError: Data provided to an operation does not meet requirements

If method parameters are out-of-range this should be a SyntaxError, if something is wrong with octet string data provided to the method then this is a DataError.

Specific cases to fix:
- validation of extractable in DH import
Comment 1 Mark Watson 2014-09-25 17:58:28 UTC
Additional cases
- validation of length fields in various cases
Comment 2 Boris Zbarsky 2014-09-25 20:21:05 UTC
SyntaxError should be a syntax error, no?

Out-of-range in Web IDL throws a TypeError.  It might be good to just align with that.

Alternately you could consider RangeError, and maybe even coordinating that with Web IDL changing its out-of-range handling.
Comment 3 Boris Zbarsky 2014-09-25 20:21:36 UTC
And note that in general parameter validation failures in Web IDL throw TypeErrors.
Comment 4 Mark Watson 2014-09-25 21:48:27 UTC
That may well be a good idea. I'd like to hear what others think. For the moment I'll at least make the specification internally consistent.
Comment 6 Mark Watson 2014-09-26 17:39:35 UTC
Regarding TypeError for out-of-range cases. If the value is actually outside the range that is value for the data type, for example a negative integer provided for an unsigned int type, this makes sense.

But if the value is in-range for the type but invalid for some application-specific reason (e.g. key lengths that can only be one of a set of specific values) that seems like a different kind of out-of-range.
Comment 7 Ryan Sleevi 2014-10-07 02:58:41 UTC
(In reply to Mark Watson from comment #4)
> That may well be a good idea. I'd like to hear what others think. For the
> moment I'll at least make the specification internally consistent.

I agree with Boris that SyntaxError surprises me. DataError made some degree of sense, but it had its own set of complexity attached to it. TypeError strikes me as more internally consistent.

Or is InvalidAccessError more consistent?
Comment 8 Mark Watson 2014-10-07 14:23:07 UTC
(In reply to Ryan Sleevi from comment #7)
> (In reply to Mark Watson from comment #4)
> > That may well be a good idea. I'd like to hear what others think. For the
> > moment I'll at least make the specification internally consistent.
> 
> I agree with Boris that SyntaxError surprises me.

It's not surprising it was used this way given then definition we have (see comment #0), but I think the definition is wrong. Out-of-range is not a 'syntax' issue.

In fact I am not sure there can be any syntax problems with a method call other than missing required parameters: everything passed in is already a valid JS type and if it is not the right type this is a TypeError.

We could say "missing or invalid" in the SyntaxError definition just in case.

> DataError made some degree
> of sense, but it had its own set of complexity attached to it. TypeError
> strikes me as more internally consistent.
> 
> Or is InvalidAccessError more consistent?

We've used InvalidAccessError for cases where you try to use a key for something it cannot do: it doesn't have the right usage or extractable value or providing the wrong kind of public key to a DH derive.

Shall we switch to TypeError for the out-of-range cases ?

Note that this is dependent on the other discussion of whether we should switch to OperationError to give flexibility to implementations to delegate range checks to libraries that might not expose the reason for a failure.
Comment 9 Mark Watson 2014-10-30 16:40:43 UTC
Agreed at f2f to switch to TypeError for out-of-range cases.
Comment 10 Mark Watson 2014-10-30 23:25:06 UTC
https://dvcs.w3.org/hg/webcrypto-api/rev/b8f161c372a5

There is one common case where SyntaxError is used which I have left as a SyntaxError. This is the case where incorrect usages are supplied. That is, recognized usage values, but incorrect for the type of key being generated, imported or unwrapped.

It doesn't seem right to call this a TypeError, since as far as the usages data type is concerned the information is correct. Please re-open if you disagree.