dagger/dagger · error

decode sdk init args: %w

Error message

decode sdk init args: %w

What it means

DecodeInitArgs parses the raw JSON blob of SDK init arguments into a map. This error wraps a JSON decode failure: the raw payload is not a JSON object (or is malformed JSON). Dagger uses json.Decoder with UseNumber to preserve numeric fidelity.

Source

Thrown at core/sdk/module_init.go:167

		}
	}
	slices.Sort(unknown)
	if len(unknown) > 0 {
		return nil, fmt.Errorf("unknown sdk %s arg(s): %v", fn.Name, unknown)
	}

	return named, nil
}

func DecodeInitArgs(raw core.JSON) (map[string]any, error) {
	if len(raw) == 0 {
		return nil, nil
	}
	var args map[string]any
	dec := json.NewDecoder(bytes.NewReader(raw.Bytes()))
	dec.UseNumber()
	if err := dec.Decode(&args); err != nil {
		return nil, fmt.Errorf("decode sdk init args: %w", err)
	}
	return args, nil
}

View on GitHub (pinned to 82ba2681db)

Solutions

  1. Validate the JSON string is well-formed with a linter/parser before passing it in.
  2. Ensure the payload is a JSON object ({...}) whose values are all valid JSON scalars/objects.
  3. If config comes from a file, re-serialize it with a JSON encoder instead of string concatenation.
  4. Check the wrapped inner error for the exact byte offset of the syntax error.

Example fix

// before
raw := core.JSON(`layout=3`)                 // not JSON
// after
raw, _ := json.Marshal(map[string]any{"layout": 3}) // {"layout":3}
Defensive patterns

Strategy: validation

Validate before calling

var probe map[string]any
if err := json.Unmarshal(rawConfig, &probe); err != nil {
    return fmt.Errorf("init args must be a JSON object: %w", err)
}

Type guard

func isJSONObject(raw []byte) bool {
    var m map[string]any
    return json.Unmarshal(raw, &m) == nil
}

Try / catch

args, err := sdk.DecodeInitArgs(raw)
if err != nil {
    if strings.Contains(err.Error(), "decode sdk init args") {
        // treat as invalid config: surface a user-facing validation message
    }
    return err
}

Prevention

When it happens

Trigger: Calling DecodeInitArgs (core/sdk/module_init.go:159-170) with a non-empty raw core.JSON that is malformed, or a valid JSON array/string/number rather than an object (decoding into map[string]any fails).

Common situations: A caller (e.g. an SDK wrapper) passing user config through without validating it's a JSON object; hand-edited dagger.json or CLI flags producing invalid JSON; encoding bugs in upstream tooling.

Related errors


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