Skip to content

Add an ErrorEvent. #53

Closed
Closed

Description

@riju

It would be nice to add an ErrorEvent to nicely handle errors in the error EventListener. I understand with promises we can always reject Promise and throw errors that we cannot escape, but for other "minor" errors it's good to handle the onerror EventListener. It will help us to distinguish different kinds of errors, temporary vs permanent, etc.

const videoDecoder = new VideoDecoder({
  output: someCanvas
});

videoDecoder.configure({codec: 'vp8'}).then(() => {
  streamEncodedChunks(videoDecoder.decode.bind(videoDecoder));
}).catch(() => {
  // App provides fallback logic when config not supported.
  ...
});
...

videoDecoder.onerror = event => {
    console.log("Error!  ");
  };

OR 

videoDecoder.addEventListener('error', error => console.log(`Error: ${error.name}`));

Strawman proposal :

[SecureContext, Exposed=(DedicatedWorker, Window)]
interface WebcodecsErrorEvent : Event {
  constructor(DOMString type, WebcodecsErrorEventInit errorEventInitDict);
  readonly attribute DOMException error;
};

dictionary WebcodecsErrorEventInit : EventInit {
  required DOMException error;
};


interface VideoDecoder {
  ...
  attribute EventHandler onerror;
}

Somewhat related to #49

Activity

  1. kenchris commented on May 18, 2020

    @kenchris

    You want this as a global error handler? Like will the event also fire for rejected promises? Would be good to check what the precedent is for this behavior

  2. dalecurtis commented on May 20, 2020

    @dalecurtis
    Contributor

    As noted in the meeting, since the rest of the API uses callbacks, I don't think we should mixin events for consistency.

  3. chcunningham commented on Oct 22, 2020

    @chcunningham
    Collaborator

    API has changed a lot since this was filed. There are now two types of errors and they're surfaced in different ways.

    Non-fatal errors are detected synchronously in response to an API call and surfaced via exception. An example would be calling configure() or decode() with inputs that are missing required parameters. The state of the codec is not altered by these errors.

    Fatal errors are detected while decoding/encoding, surfaced via the error callback. Generally these are codec errors, often caused by corrupt input.

    Please open new issues for feedback on this design.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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