Skip to content

Instantly share code, notes, and snippets.

@mzorz
Created March 24, 2020 11:40
Show Gist options
  • Save mzorz/6dcb643473418120a048673cbd7c1f6d to your computer and use it in GitHub Desktop.
Save mzorz/6dcb643473418120a048673cbd7c1f6d to your computer and use it in GitHub Desktop.
Throwing exceptions on purpose to test error notification flow
diff --git a/photoeditor/src/main/java/com/automattic/photoeditor/PhotoEditor.kt b/photoeditor/src/main/java/com/automattic/photoeditor/PhotoEditor.kt
index 4223f0c..17b2eec 100644
--- a/photoeditor/src/main/java/com/automattic/photoeditor/PhotoEditor.kt
+++ b/photoeditor/src/main/java/com/automattic/photoeditor/PhotoEditor.kt
@@ -634,6 +634,8 @@ class PhotoEditor private constructor(builder: Builder) :
fun saveImageFromPhotoEditorViewAsLoopFrameFile(sequenceId: Int, photoEditorView: PhotoEditorView): File {
val localFile = FileUtils.getLoopFrameFile(context, false, sequenceId.toString())
localFile.createNewFile()
+ // TODO REMOVE THIS TEST CODE
+ throw Exception("TEST EXCEPTION")
val saveSettings = SaveSettings.Builder()
.setClearViewsEnabled(true)
.setTransparencyEnabled(false)
@@ -714,6 +716,12 @@ class PhotoEditor private constructor(builder: Builder) :
}
}
+ // TODO REMOVE THIS CODE
+ if (TEST_FLAG == 0) {
+ TEST_FLAG = 1 // fail only once
+ throw Exception("TEST EXCEPTION IN PHOTOEDITOR")
+ }
+
Mp4Composer(videoInputPath, videoOutputPath)
.with(context)
// .size(width, height)
@@ -981,6 +989,7 @@ class PhotoEditor private constructor(builder: Builder) :
companion object {
private const val TAG = "PhotoEditor"
+ private var TEST_FLAG = 0
private fun convertEmoji(emoji: String): String {
return try {
diff --git a/mp4compose/src/main/java/com/daasuu/mp4compose/composer/Mp4ComposerEngine.kt b/mp4compose/src/main/java/com/daasuu/mp4compose/composer/Mp4ComposerEngine.kt
index eaccc2b..71bad1f 100755
--- a/mp4compose/src/main/java/com/daasuu/mp4compose/composer/Mp4ComposerEngine.kt
+++ b/mp4compose/src/main/java/com/daasuu/mp4compose/composer/Mp4ComposerEngine.kt
@@ -281,6 +281,13 @@ internal class Mp4ComposerEngine {
)
val progress = (videoProgress + audioProgress) / 2.0
if (progressCallback != null) {
+ // TODO DELETE this piece, this is just a test to break the code and simulate an exception\
+ // while a save to disk operation is happening.
+ if (progress > 0.8 && TEST_FLAG == 0) {
+ TEST_FLAG = 1 // fail only once!
+ // TODO REMOVE THIS CODE
+ throw Exception("TEST EXCEPTION IN mp4Composer")
+ }
progressCallback!!.onProgress(progress)
}
}
@@ -366,6 +373,7 @@ internal class Mp4ComposerEngine {
private val PROGRESS_UNKNOWN = -1.0
private val SLEEP_TO_WAIT_TRACK_TRANSCODERS: Long = 10
private val PROGRESS_INTERVAL_STEPS: Long = 10
+ private var TEST_FLAG = 0
private val BIT_RATE = 2000000
private val FRAME_RATE = 20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment