Skip to content

Commit

Permalink
fix: catch exception when parsing file for transcription
Browse files Browse the repository at this point in the history
  • Loading branch information
dixidroid committed Sep 10, 2024
1 parent c0cd6de commit 8f33672
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
17 changes: 13 additions & 4 deletions core/src/main/java/org/openedx/core/module/TranscriptManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.openedx.core.module.download.AbstractDownloader
import org.openedx.core.utils.Directories
import org.openedx.core.utils.FileUtil
import org.openedx.core.utils.IOUtils
import org.openedx.core.utils.Logger
import org.openedx.core.utils.Sha1Util
import subtitleFile.FormatSRT
import subtitleFile.TimedTextObject
Expand All @@ -20,6 +21,8 @@ class TranscriptManager(
val context: Context,
) {

private val logger = Logger(TAG)

private val transcriptDownloader = object : AbstractDownloader() {
override val client: OkHttpClient
get() = OkHttpClient.Builder().build()
Expand Down Expand Up @@ -67,9 +70,11 @@ class TranscriptManager(
)
if (result) {
getInputStream(downloadLink)?.let {
val transcriptTimedTextObject =
convertIntoTimedTextObject(it)
transcriptObject = transcriptTimedTextObject
try {
transcriptObject = convertIntoTimedTextObject(it)
} catch (e: NullPointerException) {
logger.e(throwable = e, submitCrashReport = true)
}
}
}
}
Expand All @@ -83,7 +88,7 @@ class TranscriptManager(
try {
transcriptObject = convertIntoTimedTextObject(transcriptInputStream)
} catch (e: Exception) {
e.printStackTrace()
logger.e(throwable = e, submitCrashReport = true)
}
} else {
startTranscriptDownload(transcriptUrl)
Expand Down Expand Up @@ -127,4 +132,8 @@ class TranscriptManager(
}
return null
}

private companion object {
const val TAG = "TranscriptManager"
}
}
16 changes: 15 additions & 1 deletion core/src/main/java/org/openedx/core/utils/Logger.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
package org.openedx.core.utils

import android.util.Log
import com.google.firebase.crashlytics.FirebaseCrashlytics
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
import org.openedx.core.BuildConfig
import org.openedx.core.config.Config

class Logger(private val tag: String) : KoinComponent {

private val config by inject<Config>()

class Logger(private val tag: String) {
fun d(message: () -> String) {
if (BuildConfig.DEBUG) Log.d(tag, message())
}
Expand All @@ -12,6 +19,13 @@ class Logger(private val tag: String) {
if (BuildConfig.DEBUG) Log.e(tag, message())
}

fun e(throwable: Throwable, submitCrashReport: Boolean = false) {
if (BuildConfig.DEBUG) throwable.printStackTrace()
if (submitCrashReport && config.getFirebaseConfig().enabled) {
FirebaseCrashlytics.getInstance().recordException(throwable)
}
}

fun i(message: () -> String) {
if (BuildConfig.DEBUG) Log.i(tag, message())
}
Expand Down

0 comments on commit 8f33672

Please sign in to comment.