Skip to content

Specify error mappings #57

Open
Open
web-platform-tests/wpt@b20e834#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 and NotAllowedError always indicates the site needs to requestPermission()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
    • No permission at the API level (i.e. need to requestPermission())
  • NoModificationAllowedError
    • Cannot acquire a lock to the handle
    • Handle lacks read or write permission at the OS level (for example, trying to get write permission on a read-only file). This should only be relevant outside of the OPFS
  • InvalidModificationError
    • Attempting to overwrite a file via move()
  • QuotaExceededError
    • Operation will exceed quota
  • TypeMismatchError
    • The handle type (file/dir) does not match what's on disk
  • AbortError
    • Using a not-yet-launched feature (i.e. directory move())
    • Some internal errors
  • InvalidStateError
    • Attempting to close an already-closed writable or SyncAccessHandle
    • Some internal errors

Some errors are mostly relevant outside of the OPFS:

  • AbortError (in addition to above)
    • Picker selection cancelled
    • File save/move blocked by Safe Browsing
  • InvalidStateError (in addition to above)
    • Trying to show a picker in a detached frame
  • SecurityError
    • Trying to show picker in sandboxed iframe/opaque origin/third party context/without user gesture

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

      Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant