Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Propagate native export error details

Prateek Sunale2fc1379f907
diff --git a/mobile/apps/photos/lib/ui/tools/editor/video_editor_page.dart b/mobile/apps/photos/lib/ui/tools/editor/video_editor_page.dart
index 37d6e4b941..4a69907580 100644
--- a/mobile/apps/photos/lib/ui/tools/editor/video_editor_page.dart
+++ b/mobile/apps/photos/lib/ui/tools/editor/video_editor_page.dart
@@ -335,14 +335,29 @@ class _VideoEditorPageState extends State<VideoEditorPage> {
}
},
onError: (e, s) {
- _logger.severe("Error exporting video with native", e, s);
+ if (e is NativeVideoEditorException) {
+ _logger.severe(
+ "Error exporting video with native (code=${e.code}, details=${e.details})",
+ e,
+ s,
+ );
+ } else {
+ _logger.severe("Error exporting video with native", e, s);
+ }
},
);
} catch (nativeError, _) {
- _logger.warning(
- "Native export failed, attempting FFmpeg fallback",
- nativeError,
- );
+ if (nativeError is NativeVideoEditorException) {
+ _logger.warning(
+ "Native export failed, attempting FFmpeg fallback (code=${nativeError.code}, details=${nativeError.details})",
+ nativeError,
+ );
+ } else {
+ _logger.warning(
+ "Native export failed, attempting FFmpeg fallback",
+ nativeError,
+ );
+ }
if (flagService.internalUser && mounted) {
showShortToast(context, "(i) Switching to FFmpeg fallback");
diff --git a/mobile/packages/native_video_editor/android/src/main/kotlin/io/ente/native_video_editor/NativeVideoEditorPlugin.kt b/mobile/packages/native_video_editor/android/src/main/kotlin/io/ente/native_video_editor/NativeVideoEditorPlugin.kt
index bb3ecf6fc3..6d2ffee887 100644
--- a/mobile/packages/native_video_editor/android/src/main/kotlin/io/ente/native_video_editor/NativeVideoEditorPlugin.kt
+++ b/mobile/packages/native_video_editor/android/src/main/kotlin/io/ente/native_video_editor/NativeVideoEditorPlugin.kt
@@ -78,7 +78,7 @@ class NativeVideoEditorPlugin : FlutterPlugin, MethodCallHandler, EventChannel.S
} catch (e: Exception) {
// Log.e(TAG, "Trim failed", e)
withContext(Dispatchers.Main) {
- result.error("TRIM_ERROR", e.message, null)
+ result.error("TRIM_ERROR", e.message, buildErrorDetails(e))
}
} finally {
currentJob = null
@@ -118,7 +118,7 @@ class NativeVideoEditorPlugin : FlutterPlugin, MethodCallHandler, EventChannel.S
} catch (e: Exception) {
// Log.e(TAG, "Rotation failed", e)
withContext(Dispatchers.Main) {
- result.error("ROTATE_ERROR", e.message, null)
+ result.error("ROTATE_ERROR", e.message, buildErrorDetails(e))
}
} finally {
currentJob = null
@@ -164,7 +164,7 @@ class NativeVideoEditorPlugin : FlutterPlugin, MethodCallHandler, EventChannel.S
} catch (e: Exception) {
// Log.e(TAG, "Crop failed", e)
withContext(Dispatchers.Main) {
- result.error("CROP_ERROR", e.message, null)
+ result.error("CROP_ERROR", e.message, buildErrorDetails(e))
}
} finally {
currentJob = null
@@ -186,7 +186,7 @@ class NativeVideoEditorPlugin : FlutterPlugin, MethodCallHandler, EventChannel.S
}
} catch (e: Exception) {
withContext(Dispatchers.Main) {
- result.error("INFO_ERROR", e.message, null)
+ result.error("INFO_ERROR", e.message, buildErrorDetails(e))
}
} finally {
currentJob = null
@@ -318,7 +318,7 @@ class NativeVideoEditorPlugin : FlutterPlugin, MethodCallHandler, EventChannel.S
} catch (e: Exception) {
// Log.e(TAG, "Process video failed", e)
withContext(Dispatchers.Main) {
- result.error("PROCESS_ERROR", e.message, null)
+ result.error("PROCESS_ERROR", e.message, buildErrorDetails(e))
}
} finally {
currentJob = null
@@ -339,4 +339,29 @@ class NativeVideoEditorPlugin : FlutterPlugin, MethodCallHandler, EventChannel.S
override fun onCancel(arguments: Any?) {
progressEventSink = null
}
+
+ private fun buildErrorDetails(throwable: Throwable): Map<String, Any?> {
+ val details = mutableMapOf<String, Any?>(
+ "type" to throwable::class.java.simpleName,
+ "message" to (throwable.message ?: "")
+ )
+
+ val exportException = when {
+ throwable is ExportException -> throwable
+ throwable.cause is ExportException -> throwable.cause as ExportException
+ else -> null
+ }
+
+ exportException?.let {
+ details["errorCode"] = it.errorCode
+ }
+
+ val rootCause = throwable.cause ?: exportException?.cause
+ rootCause?.let {
+ details["causeType"] = it::class.java.simpleName
+ details["causeMessage"] = it.message ?: ""
+ }
+
+ return details
+ }
}
diff --git a/mobile/packages/native_video_editor/lib/native_video_editor.dart b/mobile/packages/native_video_editor/lib/native_video_editor.dart
index 3d1d9234be..6150e075d3 100644
--- a/mobile/packages/native_video_editor/lib/native_video_editor.dart
+++ b/mobile/packages/native_video_editor/lib/native_video_editor.dart
@@ -3,6 +3,24 @@ import 'dart:io';
import 'package:flutter/services.dart';
+class NativeVideoEditorException implements Exception {
+ NativeVideoEditorException(
+ this.message, {
+ this.code,
+ this.details,
+ this.cause,
+ });
+
+ final String message;
+ final String? code;
+ final Object? details;
+ final Object? cause;
+
+ @override
+ String toString() =>
+ 'NativeVideoEditorException(message: $message, code: $code, details: $details)';
+}
+
class VideoEditResult {
final String outputPath;
final bool isReEncoded;
@@ -29,11 +47,11 @@ class VideoTrimParams {
});
Map<String, dynamic> toMap() => {
- 'inputPath': inputPath,
- 'outputPath': outputPath,
- 'startTimeMs': startTime.inMilliseconds,
- 'endTimeMs': endTime.inMilliseconds,
- };
+ 'inputPath': inputPath,
+ 'outputPath': outputPath,
+ 'startTimeMs': startTime.inMilliseconds,
+ 'endTimeMs': endTime.inMilliseconds,
+ };
}
class VideoRotateParams {
@@ -48,10 +66,10 @@ class VideoRotateParams {
}) : assert(degrees == 90 || degrees == 180 || degrees == 270);
Map<String, dynamic> toMap() => {
- 'inputPath': inputPath,
- 'outputPath': outputPath,
- 'degrees': degrees,
- };
+ 'inputPath': inputPath,
+ 'outputPath': outputPath,
+ 'degrees': degrees,
+ };
}
class VideoCropParams {
@@ -74,20 +92,21 @@ class VideoCropParams {
});
Map<String, dynamic> toMap() => {
- 'inputPath': inputPath,
- 'outputPath': outputPath,
- 'x': x,
- 'y': y,
- 'width': width,
- 'height': height,
- 'forceReEncode': forceReEncode,
- };
+ 'inputPath': inputPath,
+ 'outputPath': outputPath,
+ 'x': x,
+ 'y': y,
+ 'width': width,
+ 'height': height,
+ 'forceReEncode': forceReEncode,
+ };
}
class NativeVideoEditor {
static const MethodChannel _channel = MethodChannel('native_video_editor');
- static const EventChannel _progressChannel =
- EventChannel('native_video_editor/progress');
+ static const EventChannel _progressChannel = EventChannel(
+ 'native_video_editor/progress',
+ );
/// Trim video without re-encoding when possible
/// Returns the output file path
@@ -117,7 +136,12 @@ class NativeVideoEditor {
processingTime: stopwatch.elapsed,
);
} on PlatformException catch (e) {
- throw Exception('Failed to trim video: ${e.message}');
+ throw NativeVideoEditorException(
+ 'Failed to trim video: ${e.message}',
+ code: e.code,
+ details: e.details,
+ cause: e,
+ );
}
}
@@ -147,7 +171,12 @@ class NativeVideoEditor {
processingTime: stopwatch.elapsed,
);
} on PlatformException catch (e) {
- throw Exception('Failed to rotate video: ${e.message}');
+ throw NativeVideoEditorException(
+ 'Failed to rotate video: ${e.message}',
+ code: e.code,
+ details: e.details,
+ cause: e,
+ );
}
}
@@ -176,7 +205,12 @@ class NativeVideoEditor {
processingTime: stopwatch.elapsed,
);
} on PlatformException catch (e) {
- throw Exception('Failed to crop video: ${e.message}');
+ throw NativeVideoEditorException(
+ 'Failed to crop video: ${e.message}',
+ code: e.code,
+ details: e.details,
+ cause: e,
+ );
}
}
@@ -261,7 +295,12 @@ class NativeVideoEditor {
await progressSubscription?.cancel();
}
} on PlatformException catch (e) {
- throw Exception('Failed to process video: ${e.message}');
+ throw NativeVideoEditorException(
+ 'Failed to process video: ${e.message}',
+ code: e.code,
+ details: e.details,
+ cause: e,
+ );
}
}
@@ -279,7 +318,12 @@ class NativeVideoEditor {
return Map<String, dynamic>.from(result);
} on PlatformException catch (e) {
- throw Exception('Failed to get video info: ${e.message}');
+ throw NativeVideoEditorException(
+ 'Failed to get video info: ${e.message}',
+ code: e.code,
+ details: e.details,
+ cause: e,
+ );
}
}
@@ -288,7 +332,12 @@ class NativeVideoEditor {
try {
await _channel.invokeMethod('cancelProcessing');
} on PlatformException catch (e) {
- throw Exception('Failed to cancel processing: ${e.message}');
+ throw NativeVideoEditorException(
+ 'Failed to cancel processing: ${e.message}',
+ code: e.code,
+ details: e.details,
+ cause: e,
+ );
}
}