argoproj/argo-workflows · error

failed to marshal evaluated marshaled expression %q

Error message

failed to marshal evaluated marshaled expression %q

What it means

Final guard in expressionReplaceCore: json.Marshal either failed or produced nil after evaluation, which should not be reachable when the earlier allowUnresolved branches ran. Seeing it means an internal inconsistency between the marshal result and the error state.

Source

Thrown at util/template/expression_template.go:269

		log.WithError(err).Debug(ctx, "Result and error are unresolved")
		return fmt.Fprintf(w, "{{%s%s}}", kindExpression, expression)
	}
	if err != nil {
		return 0, fmt.Errorf("failed to evaluate expression: %w", err)
	}
	if result == nil {
		return 0, fmt.Errorf("failed to evaluate expression %q", expression)
	}
	resultMarshaled, err := json.Marshal(result)
	if (err != nil || resultMarshaled == nil) && allowUnresolved {
		log.WithError(err).Debug(ctx, "resultMarshaled is nil and unresolved is allowed ")
		return fmt.Fprintf(w, "{{%s%s}}", kindExpression, expression)
	}
	if err != nil {
		return 0, fmt.Errorf("failed to marshal evaluated expression: %w", err)
	}
	if resultMarshaled == nil {
		return 0, fmt.Errorf("failed to marshal evaluated marshaled expression %q", expression)
	}
	marshaledLength := len(resultMarshaled)

	// Trim leading and trailing quotes. The value is being inserted into something that's already a string.
	if len(resultMarshaled) > 1 && resultMarshaled[0] == '"' && resultMarshaled[marshaledLength-1] == '"' {
		return w.Write(resultMarshaled[1 : marshaledLength-1])
	}

	resultQuoted := []byte(strconv.Quote(string(resultMarshaled)))
	return w.Write(resultQuoted[1 : len(resultQuoted)-1])
}

func EnvMap(replaceMap map[string]string) map[string]any {
	envMap := make(map[string]any)
	for k, v := range replaceMap {
		envMap[k] = v
	}
	return envMap

View on GitHub (pinned to 35bff19146)

Solutions

  1. Report as a bug with the workflow and expression that triggered it
  2. Work around by simplifying the expression's return type
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at util/template/expression_template.go:269 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of argoproj/argo-workflows@35bff19146 (2026-09-03). Data as JSON: /api/errors/62abf7d55760db3c. Report an issue: GitHub.