dagger/dagger · error

ArrayInput.New[%d]: %w

Error message

ArrayInput.New[%d]: %w

What it means

ArrayInput.New builds an ArrayInput[I] from raw input values by decoding each element with the type's Decoder. If decoding element i fails, this error wraps the decoder error with the index. It surfaces during input construction from GraphQL variables or programmatic literal values.

Source

Thrown at dagql/types.go:1356

	for i, val := range a {
		values[i] = val
	}
	return values
}

var _ InputDecoder = ArrayInput[Input]{}

func (a ArrayInput[I]) DecodeInput(val any) (Input, error) {
	switch x := val.(type) {
	case []any:
		var zero I
		decoder := zero.Decoder()

		arr := make(ArrayInput[I], len(x))
		for i, val := range x {
			elem, err := decoder.DecodeInput(val)
			if err != nil {
				return nil, fmt.Errorf("ArrayInput.New[%d]: %w", i, err)
			}
			arr[i] = elem.(I) // TODO sus
		}
		return arr, nil
	case string: // default
		var vals []any
		dec := json.NewDecoder(strings.NewReader(x))
		dec.UseNumber()
		if err := dec.Decode(&vals); err != nil {
			return nil, fmt.Errorf("decode %q: %w", x, err)
		}
		return a.DecodeInput(vals)
	default:
		return nil, fmt.Errorf("cannot create ArrayInput from %T", x)
	}
}

func (i ArrayInput[S]) ToLiteral() call.Literal {

View on GitHub (pinned to 82ba2681db)

Solutions

  1. Check the element at the reported index and conform it to the expected input type of I.
  2. Validate the array before calling New (all elements same JSON shape as I's decoder expects).
  3. If I has a custom DecodeInput, test it in isolation for the failing value.
  4. For strings, remember New falls back to JSON-decoding the whole string — ensure it is a JSON array, not a bare list.

Example fix

// before
arr, err := dagql.ArrayInput[dagql.String]{}.New([]any{123}) // int, decoder wants string
// after
arr, err := dagql.ArrayInput[dagql.String]{}.New([]any{"123"})
Defensive patterns

Strategy: validation

Validate before calling

for i, v := range x {
    if v == nil { return fmt.Errorf("element %d is nil", i) }
}

Try / catch

arr, err := dagql.ArrayInput[I]{}.New(x)
if err != nil {
    return fmt.Errorf("bad array input (fix element per reported index): %w", err)
}

Prevention

When it happens

Trigger: Calling ArrayInput[I].New with a slice x containing a value that element type I cannot DecodeInput — wrong JSON type per element (string where object expected), an element failing its custom Decoder, or nested literal shape mismatch.

Common situations: SDK/CLI code constructing inputs programmatically with elements of the wrong shape; GraphQL variables where one array item violates the input type schema; custom Input types with buggy DecodeInput implementations.

Related errors


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