{"record":{"id":"033b5b512dc8e582","repo":"apache/dolphinscheduler","slug":"execute-shell-task-error","errorCode":null,"errorMessage":"Execute shell task error","messagePattern":"Execute shell task error","errorType":"exception","errorClass":"TaskException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-task-plugin/dolphinscheduler-task-remoteshell/src/main/java/org/apache/dolphinscheduler/plugin/task/remoteshell/RemoteShellTask.java","lineNumber":107,"sourceCode":"        setAppIds(taskId);\n        taskExecutionContext.setAppIds(taskId);\n\n        initRemoteExecutor();\n    }\n\n    @Override\n    public void handle(TaskCallBack taskCallBack) throws TaskException {\n        // add task close method to release resource\n        try (RemoteExecutor executor = remoteExecutor) {\n            // construct process\n            String localFile = buildCommand();\n            int exitCode = remoteExecutor.run(taskId, localFile);\n            setExitStatusCode(exitCode);\n            remoteShellParameters.dealOutParam(remoteExecutor.getTaskOutputParams());\n        } catch (Exception e) {\n            log.error(\"shell task error\", e);\n            setExitStatusCode(EXIT_CODE_FAILURE);\n            throw new TaskException(\"Execute shell task error\", e);\n        }\n    }\n\n    @Override\n    public void cancel() throws TaskException {\n        // cancel process\n        try {\n            log.info(\"kill remote task {}\", taskId);\n            remoteExecutor.kill(taskId);\n        } catch (Exception e) {\n            throw new TaskException(\"cancel application error\", e);\n        }\n    }\n\n    /**\n     * create command\n     *\n     * @return file name","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-task-plugin/dolphinscheduler-task-remoteshell/src/main/java/org/apache/dolphinscheduler/plugin/task/remoteshell/RemoteShellTask.java#L89-L125","documentation":"RemoteShellTask.handle wraps any failure of the remote execution pipeline (uploading the script, remoteExecutor.run, dealOutParam) into TaskException(\"Execute shell task error\") and sets exit status to failure. The cause exception carries the underlying reason (often one of the RemoteExecutor errors above).","triggerScenarios":"handle() is invoked and remoteExecutor.run(taskId, localFile) throws (SSH failure, remote non-zero exit, tracking failure) or remoteShellParameters.dealOutParam(...) throws while processing output params.","commonSituations":"SSH connectivity problems from worker; remote script fails; local temp script file cannot be written/read; output-parameter (varPool) mapping references invalid keys.","solutions":["Inspect the logged 'shell task error' stack trace for the underlying RemoteExecutor cause.","Verify SSH connectivity and credentials from the worker host to the remote machine.","Test the script content locally/remotely to rule out script errors before blaming the task framework.","Check localParams/varPool output definitions match what the script actually exports."],"exampleFix":"// before: generic wrapper\nthrow new TaskException(\"Execute shell task error\", e);\n// after: include cause detail\nthrow new TaskException(\"Execute shell task error: \" + e.getMessage(), e);","handlingStrategy":"try-catch","validationCode":"// pre-validate params and connectivity before handle()\nif (!remoteShellParameters.checkParameters()) throw new IllegalStateException(\"bad params\");\n// ssh probe\nnew Socket().connect(new InetSocketAddress(host, port), 5000);","typeGuard":null,"tryCatchPattern":"try {\n    remoteShellTask.handle();\n} catch (TaskException e) {\n    logger.error(\"Remote shell task failed, root cause: {}\", e.getCause() != null ? e.getCause().toString() : \"n/a\", e);\n    setExitStatus(FAILURE); // match framework behavior\n}","preventionTips":["Always examine e.getCause() — this wrapper hides the real SSH/script failure.","Validate output param (localParams) definitions against actual script exports.","Ensure the worker's temp directory is writable for the local script file."],"tags":["task-execution","remote-shell","ssh","wrapper"],"backgroundTag":"remote-command-failed","analyzedSha":"02eac45a1b6676e639fcbfb4be2243de5771b05d","analyzedAt":"2026-09-06T17:43:00.555Z","contentChangedAt":"2026-09-06T17:43:00.555Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}