amir20/dozzle · warning

failed to parse arguments

Error message

failed to parse arguments: %w

What it means

executeContainerAction parses its JSON arguments into containerActionArgs (container_id, host_id) with json.Unmarshal and wraps any parse failure as 'failed to parse arguments: %w'. The tool arguments string sent from cloud is not valid JSON or does not match the expected field types.

Solutions

  1. Validate the JSON with a linter/parser to find the syntax error at the wrapped offset
  2. Ensure argument field types match the struct: container_id and host_id must be JSON strings
  3. Check that no extra encoding (quotes around the JSON, markdown fences) wraps argsJSON
  4. Update the cloud tool schema so advertised parameters match containerActionArgs

Example fix

// before: args sent as a nested JSON string
{"args": "{\"container_id\": \"abc\"}"}
// after: plain JSON object
{"container_id": "abc", "host_id": "local"}
Defensive patterns

Strategy: validation

Validate before calling

// validate args JSON before dispatch
var probe map[string]json.RawMessage
if err := json.Unmarshal([]byte(argsJSON), &probe); err != nil {
    return fmt.Errorf("args not valid JSON: %w", err)
}
for _, k := range []string{"container_id", "host_id"} {
    if _, ok := probe[k]; !ok { return fmt.Errorf("missing %s", k) }
}

Try / catch

resp, err := executeContainerAction(ctx, name, argsJSON, deps)
var ue *json.UnmarshalTypeError
if err != nil && errors.As(err, &ue) {
    return toolErrorResponse(fmt.Sprintf("bad argument type for %s", ue.Field))
}

Prevention

When it happens

Trigger: The argsJSON passed by the cloud ToolRequest is empty, truncated, invalid JSON, or contains fields with wrong types (e.g. host_id as a number instead of string).

Common situations: LLM-generated tool arguments are malformed or wrapped in prose/markdown; schema drift between the advertised tool schema and the args struct; arguments double-encoded as JSON strings.

Understand the failure class

Background: "failed to unmarshal" / json.Unmarshal errors: why parsing a response into a Go struct fails and how to fix it — this error's family across 23 libraries.

Related errors


AI-assisted analysis of amir20/dozzle@d9463cbe21 (2026-09-07). Data as JSON: /api/errors/1e8a9b0308411fc2. Report an issue: GitHub.

Appendix: source

Thrown at internal/cloud/tools_actions.go:20

import (
	"context"
	"encoding/json"
	"fmt"

	"github.com/amir20/dozzle/internal/container"
	pb "github.com/amir20/dozzle/proto/cloud"
)

type containerActionArgs struct {
	ContainerID string `json:"container_id"`
	Host        string `json:"host_id"`
}

func executeContainerAction(ctx context.Context, name string, argsJSON string, deps ToolDeps) (*pb.CallToolResponse, error) {
	var args containerActionArgs
	if err := json.Unmarshal([]byte(argsJSON), &args); err != nil {
		return nil, fmt.Errorf("failed to parse arguments: %w", err)
	}

	action, err := resolveAction(name)
	if err != nil {
		return nil, err
	}

	hostID, containerID, err := resolveContainerRef(args.ContainerID, args.Host, deps)
	if err != nil {
		return nil, err
	}

	cs, err := deps.HostService.FindContainer(hostID, containerID, deps.Labels)
	if err != nil {
		return nil, fmt.Errorf("container not found: %w", err)
	}

	if err := cs.Action(ctx, action); err != nil {

View on GitHub (pinned to d9463cbe21)