Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9175707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:57:44+00:00 2026-06-17T16:57:44+00:00

I have a piece of code that is to run a user-provided Groovy script,

  • 0

I have a piece of code that is to run a user-provided Groovy script, as follows:

def scriptText = <something user entered>
def manager = new ScriptEngineManager()
def engine = manager.getEngineByName('Groovy')

try {
    engine.eval(scriptText)
}
catch (ScriptException e) {
    println 'Script error at line ' + e.getLineNumber() + ', column ' + e.getColumnNumber() + ': ' + e.getMessage()
}

If I deliberately put an error in the input script that is supplied, this code will print the following (containing undefined line and column numbers):

Script error at line -1, column -1: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: blah for class: Script1

I’ve also tried just calling Eval.me(scriptText), as the calling code is also Groovy, but then I get a large stack trace with the cause of the script error buried inside, as follows:

Exception in thread "main" groovy.lang.MissingPropertyException: No such property: blah for class: Script1
Possible solutions: class
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:50)
    at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:49)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:231)
    at Script1.run(Script1.groovy:6)  <---- this is the script error
    at groovy.lang.GroovyShell.evaluate(GroovyShell.java:518)
    at groovy.lang.GroovyShell.evaluate(GroovyShell.java:556)
    at groovy.lang.GroovyShell.evaluate(GroovyShell.java:527)
    at groovy.util.Eval.me(Eval.java:68)
    at groovy.util.Eval.me(Eval.java:51)
    at groovy.util.Eval$me.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
    at com.kminnovations.metrics.engine.tester.Testing.parseFile(Testing.groovy:32)
    at com.kminnovations.metrics.engine.tester.Testing$parseFile.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
    at com.kminnovations.metrics.engine.tester.MetricsEngineTester.main(MetricsEngineTester.groovy:23)

Is there a way to execute script text from within a program and get precisely the location of the error in the script, so that I can display it clearly for the user who provided it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T16:57:45+00:00Added an answer on June 17, 2026 at 4:57 pm

    I think you can still get the line by navigating to the root cause and searching for source like ScriptN.groovy, because ScriptEngineManager will automatically generate this name for every executed script.

    def manager = new ScriptEngineManager()
    def engine = manager.getEngineByName('Groovy')
    
    try {
        engine.eval(scriptText)
    } catch (javax.script.ScriptException e) {
        def cause = rootCause(e)
        def line = cause.stackTrace.find { 
            it.fileName ==~ /^Script\d+\.groovy$/ 
        }.lineNumber
        println "Line $line: $cause.message"
    }
    
    def rootCause(Exception e) {
        Throwable t = e;
        while (t.cause != null) t = t.cause;
        t
    }
    

    You might want to have more complicated rootCause like in apache.commons.ExceptionUtils

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a dropdown list with a piece of code that is run when
I have a piece of templated code that is never run, but is compiled.
I have a piece of code that makes the Visual Studio 2008 IDE run
I have a relatively small piece of initializer code that I want to run
I have a piece of code that I can run in four ways Debug
I have a piece of code that needs to run inside a Swing application
I have a button that I want to run a piece of script and
I have a piece of code that was written by someone else before the
I have this piece of code that does not work: public CartaoCidadao() { InitializeComponent();
I have this piece of code that works fine in subsonic 2.2, I migrated

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.