Skip to content

fix: polyfill Promise.try for pdfjs-serverless in Convex Node runtime#368

Merged
rossmanko merged 1 commit intomainfrom
fix/pdfjs-promise-try-polyfill
Apr 15, 2026
Merged

fix: polyfill Promise.try for pdfjs-serverless in Convex Node runtime#368
rossmanko merged 1 commit intomainfrom
fix/pdfjs-promise-try-polyfill

Conversation

@rossmanko
Copy link
Copy Markdown
Contributor

@rossmanko rossmanko commented Apr 15, 2026

Summary

  • PDF uploads were failing with Uncaught unhandledRejection: Promise.try is not a function in the fileActions:saveFile Convex action.
  • Root cause: pdfjs-serverless >=0.7.0 uses Promise.try, which is not yet available in Convex's Node runtime.
  • Fix: polyfill Promise.try at the top of convex/fileActions.ts so PDF processing works without downgrading the library (downgrading would require jumping from 1.2.2 → 0.6.0, spanning ~2 years of fixes).

Identified via Axiom query on data.function.request_id — failure was a runtime crash, not a business-logic rejection, so paid users with small PDFs were still blocked.

Test plan

  • pnpm typecheck passes
  • pnpm test — 817 tests pass
  • Deploy to Convex prod and upload a PDF to confirm the error is gone
  • Re-run Axiom query in 24h to confirm Promise.try is not a function no longer appears

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Added compatibility improvements to ensure Promise.try functionality is available across all runtime environments.

PDF uploads were failing with "Promise.try is not a function" because
pdfjs-serverless >=0.7.0 uses Promise.try, which is not available in
Convex's current Node runtime. Polyfill it at the top of the action
module so PDF processing works without downgrading the library.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 15, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
hackerai Ready Ready Preview, Comment Apr 15, 2026 1:29pm

Request Review

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 15, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 73979a41-2f21-439d-a599-4b10d70fd0df

📥 Commits

Reviewing files that changed from the base of the PR and between d6dba43 and 7d9a453.

📒 Files selected for processing (1)
  • convex/fileActions.ts

📝 Walkthrough

Walkthrough

A runtime polyfill for Promise.try is added to convex/fileActions.ts at module load time. The polyfill checks for the existence of Promise.try and provides a fallback implementation that synchronously invokes a callback and resolves its result through a new Promise.

Changes

Cohort / File(s) Summary
Promise.try Polyfill
convex/fileActions.ts
Added a runtime polyfill at module load time to provide Promise.try support for environments lacking native implementation, with fallback handling for callbacks returning values or PromiseLike objects.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

🐰 A promise, once needed yet hard to define,
Now polyfilled with care, everything's fine!
No try, no fret—we've got it all set,
The newest of features, no regrets yet! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding a Promise.try polyfill for pdfjs-serverless compatibility in the Convex Node runtime.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/pdfjs-promise-try-polyfill

Comment @coderabbitai help to get the list of available commands and usage tips.

@rossmanko rossmanko merged commit 7ede2af into main Apr 15, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant