{"record":{"id":"658a5e9d854e2dba","repo":"alibaba/arthas","slug":"32603-658a5e","errorCode":"-32603","errorMessage":"Task creation failed: {}","messagePattern":"Task creation failed: (.+?)","errorType":"error_code","errorClass":"McpError","httpStatus":null,"severity":"error","filePath":"arthas-mcp-server/src/main/java/com/taobao/arthas/mcp/server/task/ServerTaskToolHandler.java","lineNumber":264,"sourceCode":"\n        CreateTaskContext extra = new DefaultCreateTaskContext(\n                this.taskStore,\n                getTaskMessageQueue(),\n                exchange,\n                sessionId,\n                requestTtl,\n                request,\n                commandContext,\n                this.sessionManager\n        );\n\n        Map<String, Object> args = request.getArguments() != null ? request.getArguments() : Collections.emptyMap();\n\n        return taskTool.createTaskHandler().createTask(args, extra)\n                .exceptionally(ex -> {\n                    Throwable cause = ex instanceof CompletionException ? ex.getCause() : ex;\n                    if (!(cause instanceof McpError)) {\n                        throw new CompletionException(new McpError(\n                                new McpSchema.JSONRPCResponse.JSONRPCError(\n                                        McpSchema.ErrorCodes.INTERNAL_ERROR,\n                                        \"Task creation failed: \" + cause.getMessage(),\n                                        null\n                                )\n                        ));\n                    }\n                    throw new CompletionException(cause);\n                });\n    }\n\n    /** Handles automatic task polling for a task-aware tool call without task metadata. */\n    private CompletableFuture<McpSchema.CallToolResult> handleAutomaticTaskPolling(\n            McpNettyServerExchange exchange,\n            ArthasCommandContext commandContext,\n            McpSchema.CallToolRequest request,\n            TaskAwareToolSpecification taskTool) {\n","sourceCodeStart":246,"sourceCodeEnd":282,"githubUrl":"https://github.com/alibaba/arthas/blob/21cf2e9ba52b305290be7223b980ff504bb9cb5b/arthas-mcp-server/src/main/java/com/taobao/arthas/mcp/server/task/ServerTaskToolHandler.java#L246-L282","documentation":"Thrown by ServerTaskToolHandler when a task-aware tool's createTaskHandler().createTask(...) fails with a cause that is not already a McpError. The handler wraps the cause's message into a fresh McpError with ErrorCodes.INTERNAL_ERROR (-32603). If the underlying cause is already a McpError (e.g. capacity limit), it is rethrown unchanged.","triggerScenarios":"The task handler throws any RuntimeException/Error that is not a McpError — e.g. NPE, IOException, deserialization failure, argument error, or a downstream service exception; resource exhaustion in the handler.","commonSituations":"Handler bug (NPE) in createTask logic; invalid arguments causing a library exception; external service outage surfacing as a generic exception; serialization issues with task arguments.","solutions":["Inspect the wrapped cause (getCause() of the CompletionException) to find the real failure and fix it at the source.","Make the createTask handler robust: validate inputs and return a clean McpError for expected failure modes instead of letting raw exceptions escape.","Add logging inside the handler to capture the original exception before wrapping.","Fix the root cause (null checks, retries for transient downstream errors) rather than only handling the wrapped error."],"exampleFix":"// before\npublic CompletableFuture<McpSchema.Result> createTask(Map<String,Object> args, TaskExtra extra) {\n    String path = (String) args.get(\"path\"); // NPE if missing -> wrapped\n    return run(path);\n}\n\n// after\npublic CompletableFuture<McpSchema.Result> createTask(Map<String,Object> args, TaskExtra extra) {\n    String path = (String) args.get(\"path\");\n    if (path == null) {\n        return failedFuture(McpError.builder(ErrorCodes.INVALID_PARAMS)\n            .message(\"'path' is required\").build());\n    }\n    return run(path);\n}","handlingStrategy":"try-catch","validationCode":"// Validate handler inputs before delegating to createTask\npublic CompletableFuture<McpSchema.Result> createTask(Map<String,Object> args, TaskExtra extra) {\n    if (args.get(\"path\") == null) {\n        return failedFuture(McpError.builder(McpSchema.ErrorCodes.INVALID_PARAMS)\n            .message(\"'path' is required\").build());\n    }\n    return delegate.createTask(args, extra);\n}","typeGuard":null,"tryCatchPattern":"taskTool.createTaskHandler().createTask(args, extra)\n    .exceptionally(ex -> {\n        Throwable cause = ex instanceof CompletionException ? ex.getCause() : ex;\n        if (cause instanceof McpError me) throw new CompletionException(me);\n        logger.error(\"Task creation failed\", cause);\n        throw new CompletionException(new McpError(\n            new McpSchema.JSONRPCResponse.JSONRPCError(\n                McpSchema.ErrorCodes.INTERNAL_ERROR,\n                \"Task creation failed: \" + cause.getMessage(), null)));\n    }).join();","preventionTips":["Inspect the wrapped cause to find and fix the real failure.","Validate handler inputs and return clean McpErrors for expected failures.","Log the original exception inside the handler before it is wrapped.","Add null-checks and try/catch around external calls in createTask."],"tags":["mcp","task","tool-handler","internal-error","java"],"backgroundTag":null,"analyzedSha":"21cf2e9ba52b305290be7223b980ff504bb9cb5b","analyzedAt":"2026-08-14T00:57:07.243Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}