dagger/dagger · error

encode nested tool arguments: %w

Error message

encode nested tool arguments: %w

What it means

timeoutTool: json.Marshal of the nested tool's arguments failed — the arguments object contains values that cannot be serialized to JSON.

Source

Thrown at core/mcp.go:2303

		}
		duration, err := time.ParseDuration(durationArg)
		if err != nil {
			return nil, fmt.Errorf("invalid timeout duration %q: %w", durationArg, err)
		}
		toolName, ok := args["tool"].(string)
		if !ok {
			return nil, fmt.Errorf("invalid tool: expected string")
		}
		toolArgs, ok := args["arguments"].(map[string]any)
		if !ok {
			return nil, fmt.Errorf("invalid nested tool arguments: expected object")
		}
		if _, err := m.LookupTool(toolName, allTools.Order); err != nil {
			return nil, err
		}
		encodedArgs, err := json.Marshal(toolArgs)
		if err != nil {
			return nil, fmt.Errorf("encode nested tool arguments: %w", err)
		}
		ctx, cancel := context.WithTimeout(ctx, duration)
		defer cancel()

		// Run the nested call as the loop runs every tool call: under a
		// tool-call display span of its own, so the trace shows it as the
		// tool call it is with its arguments and logs rolled up beneath it,
		// and through MCP.Call, for the tool attributes, workspace binding and
		// result bounding that path applies.
		call := &LLMToolCall{CallID: toolName, Name: toolName, Arguments: JSON(encodedArgs)}
		displays := newDisplayPhases(ctx, "")
		displays.EmitToolCall(0, call.CallID, toolName, string(encodedArgs))
		res, failed := m.Call(toolCallCtx(ctx, displays.toolCalls, call.CallID), allTools.Order, call)
		endToolCallDisplay(displays.toolCalls, call.CallID, failed, res)
		if failed {
			if errors.Is(ctx.Err(), context.DeadlineExceeded) {
				return nil, fmt.Errorf("tool %q did not finish within %s: %w", toolName, duration, ctx.Err())
			}

View on GitHub (pinned to 82ba2681db)

Solutions

  1. Restrict argument values to plain JSON types
  2. Inspect the wrapped marshal error for the offending value
  3. Retry with simplified arguments
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at core/mcp.go:2303 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of dagger/dagger@82ba2681db (2026-09-05). Data as JSON: /api/errors/96fe7b72b3228420. Report an issue: GitHub.