Redo fix execution commands exceptions not being logged or sent back to plugins

The f62febbf commit mentioned that it solved "the bug where Termux:Tasker would hang indefinitely if Runtime.getRuntime().exec raised an exception, like for invalid or missing interpreter errors and Termux:Tasker wasn't notified of it. Now the errmsg will be used to send any exceptions back to Termux:Tasker and other 3rd party calls."

This however was still broken due to local design changes made to TermuxTask after testing was already done. This commit should solve that problem. Moreover, now a notification will be shown if execution commands **fail to start** that are run by plugins that don't expect the result back, like with Termux:Widget or RUN_COMMAND intent. This should make it easier for users to debug problems, since otherwise logcat needs to be looked. But logcat would still need to be looked if commands/scripts fail after they have started due to internal errors. Notifications can be disabled from Termux Settings by disabling the "Plugin Error Notifications" toggle.
This commit is contained in:
agnostic-apollo
2021-06-13 00:44:56 +05:00
parent f0f6927273
commit 5f2ccca423
2 changed files with 14 additions and 1 deletions

View File

@@ -419,6 +419,11 @@ public final class TermuxService extends Service implements TermuxTask.TermuxTas
TermuxTask newTermuxTask = TermuxTask.execute(this, executionCommand, this, false);
if (newTermuxTask == null) {
Logger.logError(LOG_TAG, "Failed to execute new TermuxTask command for:\n" + executionCommand.getCommandIdAndLabelLogString());
// If the execution command was started for a plugin, then process the error
if (executionCommand.isPluginExecutionCommand)
PluginUtils.processPluginExecutionCommandError(this, LOG_TAG, executionCommand, false);
else
Logger.logStackTracesWithMessage(LOG_TAG, "(" + executionCommand.errCode + ") " + executionCommand.errmsg, executionCommand.throwableList);
return null;
}
@@ -510,6 +515,11 @@ public final class TermuxService extends Service implements TermuxTask.TermuxTas
TermuxSession newTermuxSession = TermuxSession.execute(this, executionCommand, getTermuxTerminalSessionClient(), this, sessionName, executionCommand.isPluginExecutionCommand);
if (newTermuxSession == null) {
Logger.logError(LOG_TAG, "Failed to execute new TermuxSession command for:\n" + executionCommand.getCommandIdAndLabelLogString());
// If the execution command was started for a plugin, then process the error
if (executionCommand.isPluginExecutionCommand)
PluginUtils.processPluginExecutionCommandError(this, LOG_TAG, executionCommand, false);
else
Logger.logStackTracesWithMessage(LOG_TAG, "(" + executionCommand.errCode + ") " + executionCommand.errmsg, executionCommand.throwableList);
return null;
}

View File

@@ -70,8 +70,11 @@ public final class TermuxTask {
final String[] commandArray = ShellUtils.setupProcessArgs(executionCommand.executable, executionCommand.arguments);
if (!executionCommand.setState(ExecutionState.EXECUTING))
if (!executionCommand.setState(ExecutionState.EXECUTING)) {
executionCommand.setStateFailed(ExecutionCommand.RESULT_CODE_FAILED, context.getString(R.string.error_failed_to_execute_termux_task_command, executionCommand.getCommandIdAndLabelLogString()), null);
TermuxTask.processTermuxTaskResult(null, executionCommand);
return null;
}
Logger.logDebug(LOG_TAG, executionCommand.toString());