Skip to content

Commit

Permalink
Add stream errors breadbrumbs
Browse files Browse the repository at this point in the history
  • Loading branch information
LunarX committed Oct 23, 2024
1 parent 2ae4071 commit 8103d15
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import com.infomaniak.swisstransfer.ui.components.FileUi
import com.infomaniak.swisstransfer.ui.screen.newtransfer.NewTransferViewModel.Companion.LOCAL_COPY_FOLDER
import dagger.hilt.android.qualifiers.ApplicationContext
import io.sentry.Sentry
import io.sentry.SentryLevel
import java.io.File
import javax.inject.Inject
import javax.inject.Singleton
Expand All @@ -50,14 +51,24 @@ class UploadLocalStorage @Inject constructor(@ApplicationContext private val app
runCatching { createNewFile() }.onFailure { return null }

runCatching {
val inputStream = appContext.contentResolver.openInputStream(uri) ?: return null
val inputStream = appContext.contentResolver.openInputStream(uri) ?: run {
Sentry.withScope { scope ->
scope.level = SentryLevel.ERROR
Sentry.addBreadcrumb("During local copy of the file openInputStream returned null")
}
return null
}

inputStream.use { inputStream ->
outputStream().use { outputStream ->
inputStream.copyTo(outputStream)
}
}
}.onFailure {
Sentry.withScope { scope ->
scope.level = SentryLevel.ERROR
Sentry.addBreadcrumb("Caught an exception while copying file to local storage: $it")
}
return null
}
}
Expand Down

0 comments on commit 8103d15

Please sign in to comment.