Open a-sully opened 2 years ago
"AbortError" is very specific and mainly for abort signals only. cc @domenic
I'd also recommend considering that implementations might want some flexibility going forward so requiring rather unique exceptions might not be worthwhile if web developers aren't expected to branch on the exception names anyway.
If there's specific action an application might want to take for a specific failure mode, then tightly specifying errors would be useful. Otherwise tightly specifying errors doesn't have much benefit I can see; though specifying them avoids unintentional lock-in by developers who look for a specific (non-specced) error, and then break if it changes -- or if they use a different browser. However, we should be in alignment with how other specs do (or should) specify errors. @annevk ? @domenic ?
We throw SecurityError for some cases that violate security rules.
Instead of AbortError for non-implemented features, maybe NotSupportedError?
So you definitely need to specify the error type, and all browsers need to agree. There's no option of not specifying the error type at all.
But you don't need to make sure every error type is used perfectly and maps to distinct cases, if developers don't need to distinguish between such cases. For example, you could just always throw a TypeError
(the web platform's generic error). Or, you could just lump a bunch of error conditions together under "OperationError
" DOMException
, or "InvalidStateError
" DOMException
. That's a reasonable option.
Specific error type guidance you should be consistent with, which is unfortunately not written down or consistently applied, is:
NotAllowedError
" DOMException
for permissionsSecurityError
" DOMException
for security checksNotSupportedError
" DOMException
for not-yet-launched featuresAbortError
" DOMException
for operations that were aborted, usually in the sense of the developer requesting or causing the abort, usually via an AbortSignal
.UnknownError
" DOMException
for internal, implementation-specific issues.Note that "TypeMismatchError
" DOMException
is deprecated.
So yeah, there are some improvements you could make here to align better with the rest of the platform.
This came up in https://github.com/web-platform-tests/wpt/commit/b20e8343ce5ff1eada39dc1487b8b28ed903fff6#r85726061
Ideally API errors map uniquely to DOMExceptions, which make them actionable by the site. For example, if
NoModificationAllowedError
always indicates that a file is locked andNotAllowedError
always indicates the site needs torequestPermission()
on the handle, the site can respond differently to these errors.Currently, developers have to figure out this mapping on their own, or read the whole spec and infer this mapping. It would be nice to include a table mapping API errors to DOMExceptions that developers can use as a reference. Is there precedent for having this type of table in a spec?
That being said, it could be tricky to add a mapping that truly guarantees an error corresponds to a given API error (especially outside of the OPFS, where there's a whole host of things that could happen on the underlying OS). At the very least, here's a list of the mappings I'm aware of as a starting point...
NotAllowedError
requestPermission()
)NoModificationAllowedError
InvalidModificationError
move()
QuotaExceededError
TypeMismatchError
AbortError
move()
)InvalidStateError
Some errors are mostly relevant outside of the OPFS:
AbortError
(in addition to above)InvalidStateError
(in addition to above)SecurityError