{"record":{"id":"e5f4e06a3c6bac62","repo":"dagger/dagger","slug":"failed-to-encode-response-t-w","errorCode":null,"errorMessage":"failed to encode response %T: %w","messagePattern":"failed to encode response %T: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/mcp.go","lineNumber":2667,"sourceCode":"}\n\n// WorkspaceID returns the call.ID of the bound workspace, or nil if the LLM is\n// not bound to a workspace. Used by step() to detect (and persist) an in-step\n// workspace change, e.g. a Changeset overlaid by a tool.\nfunc (m *MCP) WorkspaceID() (*call.ID, error) {\n\tif m.workspace.Self() == nil {\n\t\treturn nil, nil\n\t}\n\treturn m.workspace.ID()\n}\n\nfunc toolStructuredResponse(val any) (string, error) {\n\tstr := new(strings.Builder)\n\tenc := json.NewEncoder(str)\n\tenc.SetEscapeHTML(false)\n\tenc.SetIndent(\"\", \"  \")\n\tif err := enc.Encode(val); err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to encode response %T: %w\", val, err)\n\t}\n\treturn str.String(), nil\n}\n\nfunc limitLines(spanID string, logs []string, limit, maxLineLen int) []string {\n\tif limit > 0 && len(logs) > limit {\n\t\tsnipped := fmt.Sprintf(\"... %d lines omitted (use ReadLogs(span: %s) to read more) ...\", len(logs)-limit, spanID)\n\t\tlogs = append([]string{snipped}, logs[len(logs)-limit:]...)\n\t}\n\tfor i, line := range logs {\n\t\tif len(line) > maxLineLen {\n\t\t\tlogs[i] = line[:maxLineLen] + fmt.Sprintf(\"[... %d chars truncated]\", len(line)-maxLineLen)\n\t\t}\n\t}\n\treturn logs\n}\n\n// limitIndirectLines abridges a captured log stream for a tool result: lines","sourceCodeStart":2649,"sourceCodeEnd":2685,"githubUrl":"https://github.com/dagger/dagger/blob/82ba2681dbe30d3547a1dc50ea495900ab5b6047/core/mcp.go#L2649-L2685","documentation":"toolStructuredResponse: json.Encoder failed to serialize the tool's structured response value — the response contains a value JSON cannot encode (NaN, Inf, func, channel, cycle).","triggerScenarios":"Thrown at core/mcp.go:2667 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the wrapped error for the unencodable field","Sanitize numeric values (NaN/Inf) and drop non-serializable fields before returning","Return a simpler response shape from the tool"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"82ba2681dbe30d3547a1dc50ea495900ab5b6047","analyzedAt":"2026-09-05T07:21:37.930Z","contentChangedAt":"2026-09-05T07:21:37.930Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}