alibaba/spring-ai-alibaba · error

msg.toString()

Error message

msg.toString()

What it means

Slf4jStErrorListener is the StringTemplate (ST) error listener wired into template rendering. On a runtime ST error it logs msg.toString() — this is the literal message text surfaced in logs, e.g. 'context ... no such property' or 'no such attribute'. NO_SUCH_PROPERTY errors are downgraded to warn (they are usually benign, e.g. optional fields); all other runtime errors are logged at error level. Rendering proceeds; the listener does not throw.

Source

Thrown at spring-ai-alibaba-agent-framework/src/main/java/com/alibaba/cloud/ai/graph/agent/renderer/Slf4jStErrorListener.java:47

	private final Logger logger;

	/* package */ Slf4jStErrorListener(Logger logger) {
		this.logger = logger;
	}

	@Override
	public void compileTimeError(STMessage msg) {
		logger.error(msg.toString());
	}

	@Override
	public void runTimeError(STMessage msg) {
		if (msg.error != ErrorType.NO_SUCH_PROPERTY) { // ignore these
			logger.error(msg.toString());
		}
		else {
			logger.warn(msg.toString());
		}
	}

	@Override
	public void IOError(STMessage msg) {
		logger.error(msg.toString());
	}

	@Override
	public void internalError(STMessage msg) {
		logger.error(msg.toString());
	}

}

View on GitHub (pinned to f82da0b50f)

Solutions

  1. Parse the msg.toString() text to identify the offending template expression/property, then fix the template or supply the missing attribute in the model.
  2. Register an ST AttributeRenderer for custom types (dates, enums) used in templates.
  3. Null-guard data before rendering (empty lists instead of null) to avoid iteration errors.
  4. If NO_SUCH_PROPERTY noise dominates, tighten templates to the actual model or pre-validate with SaaStTemplateRenderer validation mode THROW.

Example fix

// before
template.add("createdAt", entity.getCreatedAt()); // LocalDate, no renderer -> ST runtime error
// after
st.add("createdAt", entity.getCreatedAt() == null ? "" : entity.getCreatedAt().format(DateTimeFormatter.ISO_DATE));
Defensive patterns

Strategy: try-catch

Validate before calling

static void validateModel(ST st, Set<String> expectedKeys) {
    Map<String, Object> attrs = st.getAttributes();
    for (String k : expectedKeys) {
        if (!attrs.containsKey(k)) throw new IllegalArgumentException("Missing ST attribute: " + k);
    }
}

Try / catch

String rendered;
try {
    rendered = st.render();
} catch (Exception e) {
    log.error("ST render failed: {}", e.getMessage(), e);
    rendered = templateFallback;
}

Prevention

When it happens

Trigger: runTimeError is invoked by the ST engine while evaluating a rendered template: referencing an attribute that doesn't exist (other than the ignored NO_SUCH_PROPERTY case), invoking a malformed expression, or an incompatible renderer/converter — msg.toString() is what appears in your log.

Common situations: 1) Template references a key absent from the model (typo or renamed field) that isn't caught by NO_SUCH_PROPERTY filtering. 2) Iterating a null collection inside a template. 3 Passing a value whose type has no registered ST renderer (e.g. LocalDate without an AttributeRenderer). 4 Reading these messages in noisy logs and wanting to promote/demote them.

Understand the failure class

Background: "invalid response format", "malformed payload", "missing data field": when an API returns 200 but the response shape is wrong — this error's family across 23 libraries.

Related errors


AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09). Data as JSON: /api/errors/62d993854f71a77c. Report an issue: GitHub.