plandex-ai/plandex · error

unmarshal error: %w

Error message

unmarshal error: %w

What it means

After the document passes gojsonschema validation, validateJSON unmarshals the cleaned JSON into the concrete generic type T. This error means the JSON is structurally valid but does not decode into T — typically wrong field types (string where number expected, object where array expected).

Source

Thrown at app/cli/schema/schemas.go:78

	schemaLoader := newEmbeddedSchemaLoader(schemaPath)
	documentLoader := gojsonschema.NewBytesLoader(jsonData)

	result, err := gojsonschema.Validate(schemaLoader, documentLoader)
	if err != nil {
		return zero, err
	}
	if !result.Valid() {
		var msgs []string
		for _, d := range result.Errors() {
			msgs = append(msgs, "• "+d.String())
		}
		return zero, errors.New(strings.Join(msgs, "\n"))
	}

	var v T
	if err := json.Unmarshal(jsonData, &v); err != nil {
		return zero, fmt.Errorf("unmarshal error: %w", err)
	}
	return v, nil
}

func newEmbeddedSchemaLoader(source SchemaPath) *embeddedSchemaLoader {
	return &embeddedSchemaLoader{
		source: string(source),
		fs:     schemaFS,
	}
}

func (l *embeddedSchemaLoader) JsonSource() interface{} {
	return l.source
}

func (l *embeddedSchemaLoader) LoadJSON() (interface{}, error) {
	// remove both "./" and the scheme prefix
	source := strings.TrimPrefix(l.source, "./")

View on GitHub (pinned to e2d772072e)

Solutions

  1. Check the wrapped json.Unmarshal message naming the mismatched field/type
  2. Compare your JSON against the JSON schema for the expected types
  3. Fix field types (remove quotes around numbers, correct nesting)
  4. Regenerate the config from a known-good template

Example fix

// before
{"maxTokens": "4096"}
// after
{"maxTokens": 4096}
Defensive patterns

Strategy: validation

Validate before calling

// decode into T yourself first with strict errors to get a precise message
var probe T
if err := json.Unmarshal(data, &probe); err != nil {
    return fmt.Errorf("input does not match expected shape: %w", err)
}

Type guard

func decodesAs[T any](b []byte) bool {
    var v T
    return json.Unmarshal(b, &v) == nil
}

Try / catch

err := ValidateModelsInputJSON(data)
if err != nil && strings.HasPrefix(err.Error(), "unmarshal error:") {
    var ute *json.UnmarshalTypeError
    if errors.As(err, &ute) {
        log.Printf("field %s: expected %s", ute.Field, ute.Type)
    }
}

Prevention

When it happens

Trigger: ValidateModelsInputJSON / ValidateModelPackInlineJSON given JSON that is valid but whose fields don't match T's Go types: e.g. "maxTokens": "4096" (string) instead of a number, or a flat object where a nested object is required.

Common situations: Hand-edited model config with quoted numbers; schema validation passing because additionalProperties was relaxed but the typed struct is stricter; API version drift changing field shapes.

Related errors


AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05). Data as JSON: /api/errors/777f77636eeec7af. Report an issue: GitHub.