Skip to content

Conversation

@sunyuhan1998
Copy link
Contributor

@sunyuhan1998 sunyuhan1998 commented Jun 19, 2025

As mentioned in the issue, StTemplateRenderer uses StringTemplate as the template rendering engine.

By default, StringTemplate use org.stringtemplate.v4.misc.ErrorManager#DEFAULT_ERROR_LISTENER as the error listener for rendering exceptions, which outputs errors using System.err.println.

public static STErrorListener DEFAULT_ERROR_LISTENER = new STErrorListener() {
        public void compileTimeError(STMessage msg) {
            System.err.println(msg);
        }

        public void runTimeError(STMessage msg) {
            if (msg.error != ErrorType.NO_SUCH_PROPERTY) {
                System.err.println(msg);
            }

        }

        public void IOError(STMessage msg) {
            System.err.println(msg);
        }

        public void internalError(STMessage msg) {
            System.err.println(msg);
        }

        public void error(String s) {
            this.error(s, (Throwable)null);
        }

        public void error(String s, Throwable e) {
            System.err.println(s);
            if (e != null) {
                e.printStackTrace(System.err);
            }

        }
}

This can lead to users losing important information about rendering errors.

This PR introduces a custom STErrorListener that logs the exceptions to the application's logging system instead.

FIxes #3604

…teRenderer`.

`StTemplateRenderer` uses `StringTemplate` as the template rendering engine. By default, StringTemplate use `org.stringtemplate.v4.misc.ErrorManager#DEFAULT_ERROR_LISTENER` as the error listener for rendering exceptions, which outputs errors via System.err.println. This may cause users to miss important information about rendering errors. This commit introduces a custom `STErrorListener` that logs exceptions to the application's logging system instead.

Signed-off-by: Sun Yuhan <[email protected]>
@ilayaperumalg
Copy link
Member

@sunyuhan1998 Thanks for the PR!

@ericbottard ericbottard self-assigned this Oct 14, 2025
@ericbottard
Copy link
Member

Merged on main as 940bcf3

Thanks for yet another contribution @sunyuhan1998 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PromptTemplate should configure error reporting in String Template

4 participants