Skip to content

Comments

@remotion/licensing: No unhandled rejection if usage event send fails#6203

Merged
JonnyBurger merged 4 commits intomainfrom
no-unhandled-rejection
Jan 3, 2026
Merged

@remotion/licensing: No unhandled rejection if usage event send fails#6203
JonnyBurger merged 4 commits intomainfrom
no-unhandled-rejection

Conversation

@JonnyBurger
Copy link
Member

Only a log message

Copilot AI review requested due to automatic review settings January 3, 2026 09:53
@vercel
Copy link
Contributor

vercel bot commented Jan 3, 2026

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

Project Deployment Review Updated (UTC)
bugs Ready Ready Preview, Comment Jan 3, 2026 10:46am
remotion Ready Ready Preview, Comment Jan 3, 2026 10:46am

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to prevent unhandled promise rejections when usage event tracking fails due to network errors by adding network error detection and logging instead of throwing errors.

  • Adds a new isNetworkError utility function to detect network failures based on error messages
  • Updates registerUsageEvent to catch and log network errors
  • Adds licenseKey: 'free-license' to a test case to ensure usage events are sent during testing

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
packages/licensing/src/is-network-error.ts New utility function that detects network errors by checking error messages from different browsers
packages/licensing/src/register-usage-event.ts Imports and uses isNetworkError to log network failures with console.log
packages/web-renderer/src/test/frame-range.test.tsx Adds licenseKey parameter to test to enable usage event tracking in test scenarios
Comments suppressed due to low confidence (1)

packages/licensing/src/register-usage-event.ts:101

  • Network errors are logged but still re-thrown at line 101, which defeats the purpose of preventing unhandled rejections. After logging a network error, the function should return a default response instead of throwing. Consider returning a value like { billable: false, classification: 'failed' } for network errors to allow the caller to continue without handling the error.
		if (isNetworkError(err as Error)) {
			// eslint-disable-next-line no-console
			console.log('Failed to send usage event', err);
		}

		clearTimeout(timeout);
		if (err instanceof Error && err.name === 'AbortError') {
			throw new Error('Request timed out after 10 seconds');
		}

Comment on lines 89 to 90
const read = await res.json();
return read;
Copy link

Copilot AI Jan 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The response body can only be read once. Line 76 already calls res.json() to parse the response. Lines 89-90 attempt to call res.json() again, which will fail because the body stream has already been consumed. This code appears to be unreachable since all success paths return at line 79-82, and all error paths throw at line 86. Consider removing lines 89-90.

Copilot uses AI. Check for mistakes.
@JonnyBurger
Copy link
Member Author

@claude fix this:

The response body can only be read once. Line 76 already calls res.json() to parse the response. Lines 89-90 attempt to call res.json() again, which will fail because the body stream has already been consumed. This code appears to be unreachable since all success paths return at line 79-82, and all error paths throw at line 86. Consider removing lines 89-90.

@claude
Copy link

claude bot commented Jan 3, 2026

Claude finished @JonnyBurger's task in 58s —— View job


Fixed unreachable code in register-usage-event.ts ✓

Tasks

  • Read the register-usage-event.ts file to understand the code
  • Remove unreachable lines 89-90 that attempt to read response body twice
  • Commit and push the changes

Summary

Removed lines 89-90 from packages/licensing/src/register-usage-event.ts which were attempting to call res.json() a second time. This code was:

  1. Unreachable - all success paths return at lines 79-82, and all error paths throw at line 86
  2. Invalid - response bodies can only be read once, so the second res.json() call would have failed anyway

The fix has been committed and pushed to the no-unhandled-rejection branch.

--- |

Co-authored-by: Jonny Burger <JonnyBurger@users.noreply.github.com>
@JonnyBurger
Copy link
Member Author

@claude now we return nothing. throw an error instead

@claude
Copy link

claude bot commented Jan 3, 2026

Claude finished @JonnyBurger's task in 1m 1s —— View job


Fixed error handling in register-usage-event.ts ✓

Tasks

  • Read register-usage-event.ts to understand current code
  • Identify where function returns nothing and add error throw
  • Commit and push changes

Summary

Added throw new Error('Unexpected response from server') at packages/licensing/src/register-usage-event.ts:89 to handle the edge case where json.success is false but res.ok is true. This ensures the function always returns a value or throws an error, preventing it from falling through without a return statement.

The fix has been committed and pushed to the no-unhandled-rejection branch.

--- • Branch: no-unhandled-rejection

Co-authored-by: Jonny Burger <JonnyBurger@users.noreply.github.com>
@JonnyBurger JonnyBurger merged commit 4755c15 into main Jan 3, 2026
15 checks passed
@JonnyBurger JonnyBurger deleted the no-unhandled-rejection branch January 3, 2026 10:51
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