Skip to content

Commit d08f580

Browse files
committed
fix: catch exception when parsing file for transcription (#42)
1 parent 88dfc54 commit d08f580

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

core/src/main/java/org/openedx/core/module/TranscriptManager.kt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import okhttp3.OkHttpClient
55
import org.openedx.core.module.download.AbstractDownloader
66
import org.openedx.core.utils.Directories
77
import org.openedx.core.utils.IOUtils
8+
import org.openedx.core.utils.Logger
89
import org.openedx.core.utils.Sha1Util
910
import org.openedx.foundation.utils.FileUtil
1011
import subtitleFile.FormatSRT
@@ -21,6 +22,8 @@ class TranscriptManager(
2122
val fileUtil: FileUtil
2223
) {
2324

25+
private val logger = Logger(TAG)
26+
2427
private val transcriptDownloader = object : AbstractDownloader() {
2528
override val client: OkHttpClient
2629
get() = OkHttpClient.Builder().build()
@@ -68,9 +71,11 @@ class TranscriptManager(
6871
)
6972
if (result == AbstractDownloader.DownloadResult.SUCCESS) {
7073
getInputStream(downloadLink)?.let {
71-
val transcriptTimedTextObject =
72-
convertIntoTimedTextObject(it)
73-
transcriptObject = transcriptTimedTextObject
74+
try {
75+
transcriptObject = convertIntoTimedTextObject(it)
76+
} catch (e: NullPointerException) {
77+
logger.e(throwable = e, submitCrashReport = true)
78+
}
7479
}
7580
}
7681
}
@@ -84,7 +89,7 @@ class TranscriptManager(
8489
try {
8590
transcriptObject = convertIntoTimedTextObject(transcriptInputStream)
8691
} catch (e: Exception) {
87-
e.printStackTrace()
92+
logger.e(throwable = e, submitCrashReport = true)
8893
}
8994
} else {
9095
startTranscriptDownload(transcriptUrl)
@@ -128,4 +133,8 @@ class TranscriptManager(
128133
}
129134
return null
130135
}
136+
137+
private companion object {
138+
const val TAG = "TranscriptManager"
139+
}
131140
}

core/src/main/java/org/openedx/core/utils/Logger.kt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
package org.openedx.core.utils
22

33
import android.util.Log
4+
import com.google.firebase.crashlytics.FirebaseCrashlytics
5+
import org.koin.core.component.KoinComponent
6+
import org.koin.core.component.inject
47
import org.openedx.core.BuildConfig
8+
import org.openedx.core.config.Config
9+
10+
class Logger(private val tag: String) : KoinComponent {
11+
12+
private val config by inject<Config>()
513

6-
class Logger(private val tag: String) {
714
fun d(message: () -> String) {
815
if (BuildConfig.DEBUG) Log.d(tag, message())
916
}
@@ -12,6 +19,13 @@ class Logger(private val tag: String) {
1219
if (BuildConfig.DEBUG) Log.e(tag, message())
1320
}
1421

22+
fun e(throwable: Throwable, submitCrashReport: Boolean = false) {
23+
if (BuildConfig.DEBUG) throwable.printStackTrace()
24+
if (submitCrashReport && config.getFirebaseConfig().enabled) {
25+
FirebaseCrashlytics.getInstance().recordException(throwable)
26+
}
27+
}
28+
1529
fun i(message: () -> String) {
1630
if (BuildConfig.DEBUG) Log.i(tag, message())
1731
}

0 commit comments

Comments
 (0)