{"record":{"id":"d9b604b275d19ce4","repo":"apache/dolphinscheduler","slug":"parse-yaml-like-commands-and-args-failed","errorCode":null,"errorMessage":"Parse yaml-like commands and args failed","messagePattern":"Parse yaml-like commands and args failed","errorType":"exception","errorClass":"TaskException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/k8s/impl/K8sTaskExecutor.java","lineNumber":151,"sourceCode":"                EnvVar envVar = new EnvVar(param, paramValue, null);\n                envVars.add(envVar);\n            }\n        }\n\n        String commandString = k8STaskMainParameters.getCommand();\n        String argsString = k8STaskMainParameters.getArgs();\n        List<String> commands = new ArrayList<>();\n        List<String> args = new ArrayList<>();\n\n        try {\n            if (!StringUtils.isEmpty(commandString)) {\n                commands = yaml.load(commandString.trim());\n            }\n            if (!StringUtils.isEmpty(argsString)) {\n                args = yaml.load(argsString.trim());\n            }\n        } catch (Exception e) {\n            throw new TaskException(\"Parse yaml-like commands and args failed\", e);\n        }\n\n        NodeSelectorTerm nodeSelectorTerm = new NodeSelectorTerm();\n        nodeSelectorTerm.setMatchExpressions(k8STaskMainParameters.getNodeSelectorRequirements());\n\n        Affinity affinity = k8STaskMainParameters.getNodeSelectorRequirements().size() == 0 ? null\n                : new AffinityBuilder()\n                        .withNewNodeAffinity()\n                        .withNewRequiredDuringSchedulingIgnoredDuringExecution()\n                        .addNewNodeSelectorTermLike(nodeSelectorTerm)\n                        .endNodeSelectorTerm()\n                        .endRequiredDuringSchedulingIgnoredDuringExecution()\n                        .endNodeAffinity().build();\n\n        job = new JobBuilder()\n                .withApiVersion(API_VERSION)\n                .withNewMetadata()\n                .withName(k8sJobName)","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/k8s/impl/K8sTaskExecutor.java#L133-L169","documentation":"K8sTaskExecutor.buildK8sJob() uses SnakeYAML to parse the task's 'command' and 'args' strings (expected to be YAML-like lists) into Java objects. If yaml.load() throws on malformed input, it wraps the exception in TaskException(\"Parse yaml-like commands and args failed\"). The K8s Job spec cannot be built without these parsed values.","triggerScenarios":"Calling submitJob2k8s/buildK8sJob when the K8sParameters' commandString or argsString is not valid YAML, e.g. plain text not formatted as a YAML list, tabs for indentation, unquoted special characters ('{', ':', '#'), or content that parses to a non-list type.","commonSituations":"Users typing shell-style commands (e.g. `echo hello` or comma-separated values) instead of YAML list syntax like `[\"sh\",\"-c\",\"echo hello\"]`; hidden tab characters; strings starting with '{' or '*' that YAML treats specially.","solutions":["Rewrite the command/args fields as valid YAML list syntax, e.g. [\"sh\", \"-c\", \"your command\"].","Validate the YAML locally (paste into a YAML parser) before saving the task definition.","Replace tab indentation with spaces; quote values containing ':', '{', '}', '#', or leading special characters.","Confirm the parsed result is a List (the code expects list-like output), not a scalar or map."],"exampleFix":"// before (task params)\ncommand: echo hello && date\n// after\ncommand: [\"sh\", \"-c\", \"echo hello && date\"]","handlingStrategy":"validation","validationCode":"try (Yaml yaml = new Yaml()) {\n    Object parsed = yaml.load(commandString == null ? \"\" : commandString.trim());\n    if (!(parsed instanceof List)) {\n        throw new IllegalArgumentException(\"command must be a YAML list, got: \" + (parsed == null ? \"null\" : parsed.getClass().getSimpleName()));\n    }\n} catch (Exception e) {\n    throw new IllegalArgumentException(\"Invalid YAML in command/args: \" + e.getMessage(), e);\n}","typeGuard":"boolean isValidYamlList(String s) {\n    if (StringUtils.isEmpty(s)) return true; // treated as empty elsewhere\n    try {\n        return new Yaml().load(s.trim()) instanceof List;\n    } catch (Exception e) {\n        return false;\n    }\n}","tryCatchPattern":"try {\n    Object commands = yaml.load(commandString.trim());\n} catch (Exception e) {\n    log.error(\"Invalid command/args YAML: {}\", commandString, e);\n    throw new IllegalArgumentException(\"Fix command/args to YAML list form, e.g. [\\\"sh\\\",\\\"-c\\\",\\\"...\\\"]\");\n}","preventionTips":["Author command/args as YAML lists: [\"sh\", \"-c\", \"your command\"].","Never use tabs; use spaces for any YAML indentation.","Quote values containing YAML special characters (: { } # *).","Test-parse the strings in a YAML linter before saving the task."],"tags":["yaml","kubernetes","parse-error","task-configuration"],"backgroundTag":"yaml-parse-error","analyzedSha":"02eac45a1b6676e639fcbfb4be2243de5771b05d","analyzedAt":"2026-09-06T17:43:00.555Z","contentChangedAt":"2026-09-06T17:43:00.555Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}