-
Notifications
You must be signed in to change notification settings - Fork 48
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
Should MLContext.compute()
throw an exception if the inputs validation steps fail?
#633
Comments
I've been searching for precedent here, and I think I might be coming around to rejecting these as promises. A key difference between
Note that input validation errors will still be thrown by the WebIDL bindings if incorrect types are passed and for constraints like
Using the argument above, we should probably convert these thrown exceptions into promise rejections |
That's not true. Web methods that return a promise never throw synchronously. This is possible in JavaScript but considered incredibly bad API design. See: https://www.w3.org/2001/tag/doc/promises-guide#errors - as that says,
|
The Chromium/Blink implementation also takes care of this automagically - if control returns to script from a promise-vending IDL function, any thrown exceptions are turned into promise rejections. I assume other implementations have similar plumbing. |
TIL! In that case, I withdraw my suggestion that we should throw synchronously. Let's update this issue to instead ensure that all promise-bearing methods reject promises where they may currently throw? (such as steps 7 and 8 above) |
Thanks @inexorabletash and @a-sully for the discussion! According to Austin's last comment, I am going to close this issue and open a new one to track
|
Before I open a new issue, I am not sure the exceptions thrown in step 7 and 8 are converted to promise rejection automatically? As https://www.w3.org/2001/tag/doc/promises-guide#errors says
Should we make the conversation for step 7 and 8 explicitly? |
It should be automatic, but being explicit for subtle things like this is a good idea. Something like "If that throws an exception, return a promise rejected with the exception". |
Opened #634 |
Regarding to the existing
MLContext.compute()
algorithm, if input validation steps fail, it returns a rejected promise:In Chromium CL-5409549 review, @a-sully suggested these synchronous input validation steps should throw a TypeError:
Additionally, the following two steps may need to re-throw the exception of transferring an MLNamedArrayBufferViews steps because its transfer an ArrayBuffer steps will throw a TypeError if DetachArrayBuffer fails.
The text was updated successfully, but these errors were encountered: