Skip to content

Commit 5f2ccca

Browse files
Redo fix execution commands exceptions not being logged or sent back 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.
1 parent f0f6927 commit 5f2ccca

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

app/src/main/java/com/termux/app/TermuxService.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,11 @@ public synchronized TermuxTask createTermuxTask(ExecutionCommand executionComman
419419
TermuxTask newTermuxTask = TermuxTask.execute(this, executionCommand, this, false);
420420
if (newTermuxTask == null) {
421421
Logger.logError(LOG_TAG, "Failed to execute new TermuxTask command for:\n" + executionCommand.getCommandIdAndLabelLogString());
422+
// If the execution command was started for a plugin, then process the error
423+
if (executionCommand.isPluginExecutionCommand)
424+
PluginUtils.processPluginExecutionCommandError(this, LOG_TAG, executionCommand, false);
425+
else
426+
Logger.logStackTracesWithMessage(LOG_TAG, "(" + executionCommand.errCode + ") " + executionCommand.errmsg, executionCommand.throwableList);
422427
return null;
423428
}
424429

@@ -510,6 +515,11 @@ public synchronized TermuxSession createTermuxSession(ExecutionCommand execution
510515
TermuxSession newTermuxSession = TermuxSession.execute(this, executionCommand, getTermuxTerminalSessionClient(), this, sessionName, executionCommand.isPluginExecutionCommand);
511516
if (newTermuxSession == null) {
512517
Logger.logError(LOG_TAG, "Failed to execute new TermuxSession command for:\n" + executionCommand.getCommandIdAndLabelLogString());
518+
// If the execution command was started for a plugin, then process the error
519+
if (executionCommand.isPluginExecutionCommand)
520+
PluginUtils.processPluginExecutionCommandError(this, LOG_TAG, executionCommand, false);
521+
else
522+
Logger.logStackTracesWithMessage(LOG_TAG, "(" + executionCommand.errCode + ") " + executionCommand.errmsg, executionCommand.throwableList);
513523
return null;
514524
}
515525

termux-shared/src/main/java/com/termux/shared/shell/TermuxTask.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,11 @@ public static TermuxTask execute(@NonNull final Context context, @NonNull Execut
7070

7171
final String[] commandArray = ShellUtils.setupProcessArgs(executionCommand.executable, executionCommand.arguments);
7272

73-
if (!executionCommand.setState(ExecutionState.EXECUTING))
73+
if (!executionCommand.setState(ExecutionState.EXECUTING)) {
74+
executionCommand.setStateFailed(ExecutionCommand.RESULT_CODE_FAILED, context.getString(R.string.error_failed_to_execute_termux_task_command, executionCommand.getCommandIdAndLabelLogString()), null);
75+
TermuxTask.processTermuxTaskResult(null, executionCommand);
7476
return null;
77+
}
7578

7679
Logger.logDebug(LOG_TAG, executionCommand.toString());
7780

0 commit comments

Comments
 (0)