Skip to content

fix: prevent crashes on setDataSource failure and missing native module - #149

Open
gandol wants to merge 2 commits into
souvik-ghosh:masterfrom
gandol:fix/android-setdatasource-runtime-crash
Open

fix: prevent crashes on setDataSource failure and missing native module#149
gandol wants to merge 2 commits into
souvik-ghosh:masterfrom
gandol:fix/android-setdatasource-runtime-crash

Conversation

@gandol

@gandol gandol commented Jul 15, 2026

Copy link
Copy Markdown

Summary

  • Android: Catch Exception (including RuntimeException from MediaMetadataRetriever.setDataSource) so bad/unsupported video URLs reject the JS Promise instead of crashing the Android process
  • Android: Validate empty video URLs early; always release the retriever in finally; coerce headers to Map<String, String>
  • JS: Guard exports when the native module is not linked so import-time destructuring does not crash

Problem

1. Android process crash (setDataSource)

On Android, MediaMetadataRetriever.setDataSource can throw:

java.lang.RuntimeException: setDataSource failed: status = 0x80000000

This happens for empty URLs, unsupported codecs, or remote videos the retriever cannot open. The previous catch block only handled IOException | IllegalStateException, so the uncaught RuntimeException on the worker thread killed the entire app:

FATAL EXCEPTION: pool-*-thread-1
java.lang.RuntimeException: setDataSource failed: status = 0x80000000
  at android.media.MediaMetadataRetriever.setDataSource
  at CreateThumbnailModule.getBitmapAtTime

JS .catch() never runs because the process dies before the Promise is rejected.

Related: #62, #131

2. JS crash when native module is missing

export const { create: createThumbnail } = CreateThumbnail;

throws if CreateThumbnail is undefined (Expo Go, incomplete autolinking, etc.). This change uses optional chaining and rejects the Promise instead.

Test plan

  • Call createThumbnail with a valid local/remote video URL → still resolves with a thumbnail
  • Call with an empty url → Promise rejects with CreateThumbnail_ERROR (no crash)
  • Call with a bad/unsupported remote URL (e.g. one that previously caused 0x80000000) → Promise rejects (no crash)
  • Call with optional headers → still works
  • Load the package when native module is not linked → import succeeds; createThumbnail() rejects (no crash)

@gandol
gandol force-pushed the fix/android-setdatasource-runtime-crash branch 2 times, most recently from 7f18234 to c73a532 Compare July 15, 2026 04:32
gandol added 2 commits July 15, 2026 11:33
…lure

MediaMetadataRetriever.setDataSource can throw RuntimeException
(e.g. status 0x80000000 for bad/unsupported remote URLs). The previous
catch only handled IOException and IllegalStateException, so the
uncaught RuntimeException on the worker thread killed the entire app
process.

Catch Exception in create(), wrap RuntimeException in getBitmapAtTime,
validate empty URLs, and always release the retriever in finally.
Destructuring create from CreateThumbnail throws if the native module
is not linked (e.g. Expo Go, incomplete autolinking). Export safe
fallbacks that reject the Promise instead of crashing at import time.
@gandol
gandol force-pushed the fix/android-setdatasource-runtime-crash branch from c73a532 to a7cf48c Compare July 15, 2026 04:33
@gandol gandol changed the title fix(android): reject promise instead of crashing on setDataSource failure fix: prevent crashes on setDataSource failure and missing native module Jul 15, 2026
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