spring-projects/spring-ai · error

${msg.toString()}

Error message

${msg.toString()}

What it means

CommonsLoggingStErrorListener is the StringTemplate (ST) error listener used by spring-ai-template-st. When the ST engine raises a runtime error while rendering a template, this listener logs it via Commons Logging: ERROR level for real errors, WARN level for missing-property errors, which are deliberately ignored otherwise. The message text is simply the ST engine's own error description.

Source

Thrown at spring-ai-template-st/src/main/java/org/springframework/ai/template/st/CommonsLoggingStErrorListener.java:49

	private final Log logger;

	/* package */ CommonsLoggingStErrorListener(Log 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 98a7beda4f)

Solutions

  1. Read the logged ST message — it names the template and the exact property or operation that failed.
  2. Fix the placeholder/property path in the template so it matches the variables passed to render().
  3. Verify the model object exposes the referenced properties (public getters/fields accessible to ST).
  4. If the message is a NO_SUCH_PROPERTY warning, either add the missing variable to the model or use StTemplateRenderer validation to catch it upfront.

Example fix

// before: template references property that doesn't exist
StringTemplate st = new StringTemplate("Hello {userName.first}!"); // model has only 'user'
// after: align template with model
StringTemplate st = new StringTemplate("Hello {user}!");
Defensive patterns

Strategy: validation

Validate before calling

// verify placeholders match model keys before rendering
Set<String> tokens = extractPlaceholders(template);
if (!modelMap.keySet().containsAll(tokens)) { throw new IllegalArgumentException("unresolved placeholders: " + tokens); }

Prevention

When it happens

Trigger: Rendering an ST template (e.g. via StTemplateRenderer) that hits a runtime evaluation problem: referencing a property that does not exist on the model object, illegal reflective access on a property, or I/O errors — anything ST reports through RuntimeError.

Common situations: Prompt templates referencing variables with wrong property paths (obj.name where model has no 'name'); passing Maps instead of POJOs or vice versa; typos in template placeholders; using records/classes whose fields ST cannot access.

Related errors


AI-assisted analysis of spring-projects/spring-ai@98a7beda4f (2026-09-11). Data as JSON: /api/errors/6ef23e3d35b9eb97. Report an issue: GitHub.