Skip to content

crypto: WebCrypto error paths should reject with DOMException instead of resolving undefined #1431

Description

@TheHypnoo

Background

The node:crypto.subtle.* surface (perry-stdlib/src/webcrypto.rs) currently resolves to undefined on invalid inputs, missing keys, or unsupported algorithms. Node returns a rejected Promise with a DOMException("OperationError" | "NotSupportedError" | ...) in those cases.

Impact

  • Code using .catch(e => e.name === "OperationError") diverges from Node — Perry runs the then branch with undefined.
  • Parity tests that exercise error paths cannot be written against the current surface.
  • Surfaced during the Expand crypto parity coverage #1419 review; deferred as out-of-scope (157 sites, no rejection-path test coverage to validate behavior changes).

Scope

  • Add a reject_with_dom_exception(name: &str, message: &str) -> *mut Promise helper in webcrypto.rs.
  • Audit each resolve_undefined() site in webcrypto.rs (~157) and convert those that signal an error to use the new helper. Legitimate "resolve undefined" cases (e.g. void returns) stay as-is.
  • Add a parity suite for rejection behavior: test-parity/node-suite/crypto/webcrypto/errors/*.

Tracked under #793.

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