argoproj/argo-workflows · error
failed to marshal evaluated expression: %w
Error message
failed to marshal evaluated expression: %w
What it means
After successful evaluation, json.Marshal of the expression's result failed — the evaluated value cannot be serialized to JSON for insertion into the template. Rare; indicates an unserializable value (e.g. chan, func, or cyclic structure) coming out of the expression.
Source
Thrown at util/template/expression_template.go:266
result, err := expr.Run(program, env)
if (err != nil || result == nil) && (allowUnresolved || shouldAllowFailure) {
// <nil> result is also un-resolved, and any error can be unresolved
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 {View on GitHub (pinned to 35bff19146)
Solutions
- Change the expression to return a JSON-serializable type
- Avoid returning raw complex objects from custom contexts
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at util/template/expression_template.go:266 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/073d831851c7fd8e.
Report an issue: GitHub.