How to show Warning/Error message in Custom JQL Plugin

We are building a Custom JQL Plugin which can search some specific information within the issue’s custom fields. While most of the cases it works fine but for some case due to huge query processing the system gets stuck forever unless we restart the Jira system.

While we are trying to add more validation in Custom JQL Plugin but still sometime we are getting system out of memory due to large query transactions. We want to limit the same by giving some sort of error message such if number of issue returned is >5000 we want to stop processing such large query. But we are unable to post any error message via MessageSet.

I am new to the system, looking for some help and recommendations, how to show custom warning/error message when large query transactions take place. Otherwise if there is any other graceful way which we can use to stop such large transactions and notify users.