amir20/dozzle · error

failed to parse arguments

Error message

failed to parse arguments: %w

What it means

parseArgs is a generic helper that unmarshals a tool-call argsJSON string into a struct of type T. Any invalid JSON (syntax error or type mismatch against T) produces this wrapped error, which callers return as-is to the tool dispatcher.

Solutions

  1. Check the wrapped json error (errors.As for *json.UnmarshalTypeError or *json.SyntaxError) to pinpoint the bad field or offset.
  2. Ensure required tools receive a non-empty JSON object for argsJSON.
  3. Keep the Go args struct field types and json tags in sync with the schema published in AvailableTools().

Example fix

// before
args, err := parseArgs[fetchLogsArgs]("") // empty string -> parse error
// after
if argsJSON == "" { return nil, errors.New("missing required arguments") }
args, err := parseArgs[fetchLogsArgs](argsJSON)
Defensive patterns

Strategy: validation

Validate before calling

function safeArgs(obj) {
  if (obj === undefined || obj === null) throw new Error("parseArgs requires a non-empty args object");
  return JSON.stringify(obj); // guarantees syntactically valid JSON
}

Try / catch

args, err := parseArgs[fetchLogsArgs](argsJSON)
if err != nil {
    var typeErr *json.UnmarshalTypeError
    if errors.As(err, &typeErr) {
        return nil, fmt.Errorf("field %s has wrong type", typeErr.Field)
    }
    return nil, err
}

Prevention

When it happens

Trigger: Any cloud tool using parseArgs receiving argsJSON that is not valid JSON for its target struct: empty string where args are required, trailing commas, wrong field types, or double-encoded JSON.

Common situations: Tool implementations forgetting that parseArgs (unlike executeFindContainers) does not tolerate empty args; agents emitting JSON strings instead of objects; struct field type changes making previously valid payloads invalid.

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/3ec6ab068259f368. Report an issue: GitHub.

Appendix: source

Thrown at internal/cloud/tools_helpers.go:18

package cloud

import (
	"encoding/json"
	"fmt"
	"strings"
	"time"

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

// parseArgs unmarshals argsJSON into a fresh value of T.
func parseArgs[T any](argsJSON string) (T, error) {
	var args T
	if err := json.Unmarshal([]byte(argsJSON), &args); err != nil {
		return args, fmt.Errorf("failed to parse arguments: %w", err)
	}
	return args, nil
}

// buildHostNameMap creates a mapping from host ID to host name.
func buildHostNameMap(hostService ToolHostService) map[string]string {
	hosts := hostService.Hosts()
	m := make(map[string]string, len(hosts))
	for _, h := range hosts {
		m[h.ID] = h.Name
	}
	return m
}

// resolveHostName returns the host name for a given host ID, falling back to the ID itself.
func resolveHostName(hostID string, hostNames map[string]string) string {
	if name, ok := hostNames[hostID]; ok {
		return name

View on GitHub (pinned to d9463cbe21)