You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In web-sys, operations that can fail currently return Result<T, JsValue>. The WebIDL specification lists the exceptions that specification-compliant implementations may throw, namely:
EvalError
RangeError
ReferenceError
TypeError
URIError
DOMException
Since all web_sys operations are derived from WebIDL, it seems that the error type could be narrowed to the above set.
Proposed Solution
Errors thrown by the WebIDL ECMAScript bindings could be converted to Rust structs implementing Error. This would further reduce the need of exposing JS objects to the Rust code; for example, parameters are already passed as Rust values and not JsValues, so modelling errors as Rust values would further hide the JS glue layer as an implementation detail. No idea about the potential performance hit though.
Has this behaviour been considered before and what are the motivations behind the current one?
The text was updated successfully, but these errors were encountered:
The issue is that the WebIDL does not specify which errors are thrown by which methods. In fact, it doesn't even mention whether the method throws at all, which is why web-sys has to conservatively assume that all methods might throw.
In addition, the above list is not exhaustive, because other specifications can create new error types. As an example, the FileReader spec can throw NotFoundError, NotReadableError, and SecurityError. And IndexedDB can throw a whole slew of errors. And unfortunately this information isn't in the WebIDL either.
So we can't do this because the WebIDL just doesn't give enough information. However, gloo contains hand-crafted high-level APIs which can provide more meaningful error types (such as the gloo-file crate which defines a FileReadError enum).
Motivation
In
web-sys
, operations that can fail currently returnResult<T, JsValue>
. The WebIDL specification lists the exceptions that specification-compliant implementations may throw, namely:EvalError
RangeError
ReferenceError
TypeError
URIError
DOMException
Since all
web_sys
operations are derived from WebIDL, it seems that the error type could be narrowed to the above set.Proposed Solution
Errors thrown by the WebIDL ECMAScript bindings could be converted to Rust structs implementing
Error
. This would further reduce the need of exposing JS objects to the Rust code; for example, parameters are already passed as Rust values and notJsValues
, so modelling errors as Rust values would further hide the JS glue layer as an implementation detail. No idea about the potential performance hit though.Has this behaviour been considered before and what are the motivations behind the current one?
The text was updated successfully, but these errors were encountered: