-
Notifications
You must be signed in to change notification settings - Fork 28
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
Error Handling #200
Comments
I would also imagine that some of these errors can be mapped to protocols that can be then described in the Binding Templates document. This way, when there is a Consumer and an Exposed Thing communicating, even if these new errors are not sent in the application layer, the errors that are actually sent in the application layer can be translated back into these new errors in the scripting layer. For example, a consumer sends a readproperty request (GET) over HTTP to a non-existing property in the ExposedThing (even if it is shown to be available in the TD), the Exposed Thing responds with 404 Not Found. This is then translated into Even further, I think that this can be a good motivation for why one should use the Scripting API in the Exposed Thing. If you don't, then you have to know what status code to send for each protocol. |
There is (and should be) a difference between API object errors (SecurityError, TypeError etc) and errors reported by protocols in WoT interaction patterns. We need to track that across the whole API. IMHO there should NOT be error translation between protocols and Scripting objects for a few reasons:
Therefore, errors reported via WoT interactions should not be translated, but should be reported via mechanisms embedded into those interactions. Then, another problem was that TypeScript lacks some of the error definitions: but in Node and TypeScript those could be defined (the restriction only applies to browser APIs). |
So, we can use the following:
Note that
If you think that is enough to map (most) protocol errors, we could try that. However, I think it would be better if interactions had an embedded mechanism for error reporting. |
Well generally if someone properly implements a generic HTTP server, it would return the proper HTTP codes. For already existing devices, there should thus be a way to inform in the Consumer script the error codes in a non-HTTP way. Of course, we should not try to map all the errors but the most common ones, i.e. no need to map HTTP 418 I'm a teapot status code |
A table like the following can be used. Maybe we can group them according to WoT operations? readProperty( )
invokeaction( )
|
Well, of course we need to map that! Everyone supports it! :) Would the table above be informative or normative when included in the spec? |
I think we do need a catch-all case if an error code is received for which there is not a definition in the protocol binding. Should this be generic (eg NotFound for any 4xx error code) or should a special error (eg OperationError) for errors which are not defined in the protocol binding? |
Possible error causes currently used in Scripting:
Some of these need alignment and/or review. |
Some feedback to the comment above:
|
The "fetch a TD" is not part of WoT Scripting API any more: it's "outsourced" to the Fetch API or libraries. |
Fixed by #218, please check. |
I do not see the mapping to protocols, is it intended that these covered in the binding templates document? (Or maybe I couldn't find it in the document) |
Yes, Bindings should provide implementation guidance on mapping to protocols in general, including errors. This is mentioned in [almost all] the algorithms, though in a bit generic way. Maybe we could add a note or more explicit prose. Keep this open. |
Signed-off-by: Zoltan Kis <[email protected]>
Address #200: improve text on error handling
During the profiles discussion, we specified a number of HTTP error codes and also the use of the problem details body (RFC7807) if there is a body. The question is, is this information, and indeed the fact that a given protocol is even being used, available to the application upon an error? We may also have two answers to this, depending on whether we are in a privacy-sensitive context or not (or trusted code or not). I was thinking we could have generic error exception types, and then could pack additional information in the body, including the error code (protocol specific), identification of the protocol, and a copy of the response body. HOWEVER, when the runtime is set up we could specify a "trust level" and if the trust level is "untrusted" then no error details would be provided (just generic error classes). |
Yes, this is useful for the Scripting API implementation.
This is still not fully decided, see https://w3c.github.io/wot-scripting-api/#error-handling (pointing to this issue). Then, we will have to map (see comment) the errors to Error and DOMException, following the W3C TAG recommendation. Right now we do permit that (on pressure from node-wot), like in step 7 of https://w3c.github.io/wot-scripting-api/#the-readproperty-method. |
It is already that way, except that the spec algorithms say where additional error information is allowed to start with. Then the implementation will figure out if it can (from bindings) and allowed (per spec and/or security provisioning) to provide any additional error information. We need to define algorithmic formalizations for this behavior for each use case/interaction. |
TODO: define an algorithm for "parse interaction error", similar to parse interaction response, and also a mechanism/algorithm to dispatch/present error data to scripts. |
Scripting Call 2021-08-02
|
The scripting API makes use of errors being available in ECMAScript (e.g.,
TypeError
).Moreover, also other errors such as
NotSupportedError
orNotFoundError
are used which are not available in ECMAScript. Instead those errors are defined here.We need to have a good set of errors that work for JavaScript/Typescript and browser environments.
For example,
NotSupportedError
andNotFoundError
need to be defined in TypeScript definitions before they can be used in TS.The text was updated successfully, but these errors were encountered: