Skip to content

Commit

Permalink
[APT-9578] Improve Exception Handling
Browse files Browse the repository at this point in the history
ArmadilloException needs to support `cause` and `message` in the way `Exception` and most programmers expect them to be used.

Avoids initializing new `Exception()` wherever possible to prevent obfuscating the origin of an error. Never uses `object` for Exceptions, as each carry specific information on their stacktrace.

Exception messages need to be written in plain English, with indication of what component is failing when it fails. And ideally, with a hint on how to fix these errors.
  • Loading branch information
kabliz committed Aug 14, 2024
1 parent e041fc1 commit 6155a79
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ internal class ExoplayerDownloadEngine @Inject constructor(
if (hasSnowCone() && e is ForegroundServiceStartNotAllowedException) {
stateModifier.dispatch(ErrorAction(DownloadServiceLaunchedInBackground(audioPlayable.id, e)))
} else {
stateModifier.dispatch(ErrorAction(ArmadilloIOException(cause = e, whatActionFailedMessage = "Can't prepare download.")))
stateModifier.dispatch(ErrorAction(ArmadilloIOException(cause = e, actionThatFailedMessage = "Can't prepare download.")))
}
}
}

override fun onPrepareError(helper: DownloadHelper, e: IOException) =
stateModifier.dispatch(ErrorAction(ArmadilloIOException(cause = e, whatActionFailedMessage = "Can't report download error.")))
stateModifier.dispatch(ErrorAction(ArmadilloIOException(cause = e, actionThatFailedMessage = "Can't report download error.")))
})
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ data class HttpResponseCodeException(val responseCode: Int, val url: String?, ov
override val errorCode: Int = 200
}

class ArmadilloIOException(cause: Exception, whatActionFailedMessage: String)
: ArmadilloException(cause = cause, message = "A critical playback issue occurred: $whatActionFailedMessage") {
class ArmadilloIOException(cause: Exception, actionThatFailedMessage: String)
: ArmadilloException(cause = cause, message = "A critical playback issue occurred: $actionThatFailedMessage") {
override val errorCode = 201
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal fun ExoPlaybackException.toArmadilloException(): ArmadilloException {
is SocketTimeoutException -> HttpResponseCodeException(0, null, source)
is UnknownHostException ->
HttpResponseCodeException(0, source.message, source) // Message is supposed to be the host for UnknownHostException
else -> ArmadilloIOException(cause = this, whatActionFailedMessage = "Exoplayer error.")
else -> ArmadilloIOException(cause = this, actionThatFailedMessage = "Exoplayer error.")
}
}
} else if (TYPE_RENDERER == type) {
Expand Down

0 comments on commit 6155a79

Please sign in to comment.