Skip to content

Fixed GH-3604, Add STErrorListener to StTemplateRenderer. #3606

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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!

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
3 participants