dagger/dagger · error

unknown enum value %v

Error message

unknown enum value %v

What it means

For an argument whose type is an enum and which has a default value, the default must be a string naming an enum member. If argSpec.defaultValue is not a string (e.g. a number or bool), codegen cannot even look it up and fails with "unknown enum value %v".

Source

Thrown at cmd/codegen/generator/go/templates/module_funcs.go:265

			return nil, fmt.Errorf("failed to generate arg type code: %w", err)
		}
		if argSpec.optional {
			argTypeDefCode = argTypeDefCode.Dot("WithOptional").Call(Lit(true))
		}

		argOptsCode := []Code{}
		if argSpec.description != "" {
			argOptsCode = append(argOptsCode, Id("Description").Op(":").Lit(strings.TrimSpace(argSpec.description)))
		}
		if argSpec.sourceMap != nil {
			argOptsCode = append(argOptsCode, Id("SourceMap").Op(":").Add(argSpec.sourceMap.TypeDefCode()))
		}
		if argSpec.hasDefaultValue {
			var defaultValue string
			if enumType, ok := argSpec.typeSpec.(*parsedEnumTypeReference); ok {
				v, ok := argSpec.defaultValue.(string)
				if !ok {
					return nil, fmt.Errorf("unknown enum value %v", argSpec.defaultValue)
				}
				res := enumType.lookup(v)
				if res == nil {
					return nil, fmt.Errorf("unknown enum value %q", v)
				}
				defaultValue = strconv.Quote(res.name)
			} else {
				v, err := json.Marshal(argSpec.defaultValue)
				if err != nil {
					return nil, fmt.Errorf("could not encode default value %q: %w", argSpec.defaultValue, err)
				}
				defaultValue = string(v)
			}
			argOptsCode = append(argOptsCode, Id("DefaultValue").Op(":").Id("dagger").Dot("JSON").Call(Lit(defaultValue)))
		}

		if argSpec.defaultPath != "" {
			argOptsCode = append(argOptsCode, Id("DefaultPath").Op(":").Lit(argSpec.defaultPath))

View on GitHub (pinned to 82ba2681db)

Solutions

  1. Change the default value to a string matching one of the enum's member names
  2. Verify the argument's type is actually the enum you intend; fix the type if it should be an int/bool
  3. Remove the default value if none is appropriate
  4. Regenerate the module

Example fix

// before
// +default=42
	level MyEnum,

// after
// +default="high"
	level MyEnum,
Defensive patterns

Strategy: validation

Validate before calling

// ensure enum argument defaults are strings matching member names
// wrong: +default=3 on an enum arg; right: +default="memberName"

Prevention

When it happens

Trigger: Annotating an enum-typed argument with a default value that isn't a string — for example a numeric or boolean default in the pragma/annotation, or a corrupted parse that stored a non-string default.

Common situations: Copy-pasting default-value annotations from an int-typed argument to an enum-typed one; hand-writing default pragmas with wrong literal types.

Related errors


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