Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: catch exception when parsing file for transcripts #42

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
farhan-arshad-dev marked this conversation as resolved.
Show resolved Hide resolved
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
Loading