Skip to content

Commit

Permalink
GrindrPlus: Better error handling
Browse files Browse the repository at this point in the history
Change-Id: I610b34b4708d57658a9ca95cfdc3a97310909da7
  • Loading branch information
R0rt1z2 committed Jan 3, 2025
1 parent f1a3392 commit 3c72a51
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 6 additions & 4 deletions app/src/main/java/com/grindrplus/commands/CommandModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ abstract class CommandModule(
commandMethod.invoke(this, args)
true
} catch (e: Exception) {
GrindrPlus.showToast(Toast.LENGTH_LONG,
"An error occurred while executing the command: ${e.message}")
GrindrPlus.logger.log("Error executing command: $inputCommand")
e.printStackTrace()
val message = "An error occurred while executing the command: ${e.message ?: "Unknown error"}"
GrindrPlus.showToast(Toast.LENGTH_LONG, message)
GrindrPlus.logger.apply {
log(message)
writeRaw(e.stackTraceToString())
}
false
}
}
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/com/grindrplus/core/Logger.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ class Logger(logFile: String) {
logFlow.tryEmit(msg)
}

fun writeRaw(msg: String) {
try {
if (checkAndManageSize()) {
LOG_FILE.appendText(msg + "\n")
}
} catch (e: Exception) {
Log.wtf(LOG_TAG, "Failed to write raw log message: ${e.message}")
}
}

private fun checkAndManageSize(): Boolean {
if (LOG_FILE.length() > MAX_LOG_SIZE) {
manageLogOverflow()
Expand Down

0 comments on commit 3c72a51

Please sign in to comment.