Skip to content

Headless: restriction failures from the file input also surface as unhandled promise rejections #342

Description

@BSalaeddin

When a picked file fails a restriction, core.addFiles() emits restriction-failed and then rethrows:

} catch (error) {
  this.emitter.emit("restriction-failed", { error });
  throw error;
}

The onChange that getInputProps() wires onto the hidden input calls it as fire-and-forget:

if (fileList) { void addFiles(Array.from(fileList)); }

So every restriction failure through the file input produces the event (which the app handles) plus an unhandled promise rejection. In prod that means each user-facing "file too large" also logs an uncaught rejection to the console — and to Sentry — even in apps that fully handle restriction-failed. We had to add a window.onunhandledrejection filter to keep our error monitoring clean, which is not great.

Since the event is already emitted, catching inside the getter's onChange (or not rethrowing on the input path) would fix it without changing the API for callers who await addFiles() directly.

Small related thing: the restriction-failed payload is typed { error: unknown } — typing it as UpupError would remove a cast in every handler.

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