Skip to content

Commit

Permalink
Redo fix execution commands exceptions not being logged or sent back …
Browse files Browse the repository at this point in the history
…to plugins

The f62febb 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.
  • Loading branch information
agnostic-apollo committed Jun 12, 2021
1 parent f0f6927 commit 5f2ccca
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
10 changes: 10 additions & 0 deletions app/src/main/java/com/termux/app/TermuxService.java
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,11 @@ public synchronized TermuxTask createTermuxTask(ExecutionCommand executionComman
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;
}

Expand Down Expand Up @@ -510,6 +515,11 @@ public synchronized TermuxSession createTermuxSession(ExecutionCommand execution
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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,11 @@ public static TermuxTask execute(@NonNull final Context context, @NonNull Execut

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());

Expand Down

0 comments on commit 5f2ccca

Please sign in to comment.