groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Harish Dewan <harish.de...@gmail.com>
Subject Re: ScriptException does not prints actual file name
Date Sun, 19 Mar 2017 16:29:20 GMT
Hi Edmond,
thanks for your reply.
the unique number which i was talking about is not the line number.
for example: below is an script exception thrown in case of syntax error.
I had introduced text 'abcd' in my hello.groovy script.
in case of exception it says below message

javax.script.ScriptException: groovy.lang.MissingPropertyException: No such
property: abcd for class: Script3

again if i re run the same code, it just increments the Script<unique
number> i.e Script4, Script5 and so on.

I was expecting error message of type
javax.script.ScriptException: groovy.lang.MissingPropertyException: No such
property: abcd for class: hello.groovy

I am setting the context as follows

ScriptEngine engine = new ScriptEngineManager(loader)
.getEngineByExtension(extension);
ScriptContext context = engine.getContext();
context.setAttribute(ScriptEngine.FILENAME, "hello.groovy",
ScriptContext.ENGINE_SCOPE);

Reader r = new FileReader("<path to hello.groovy file>");
try
{
engine.eval(r,context);
}
catch (ScriptException e)
{
}

I did tried looking into source code and in class
'GroovyScriptEngineImpl.java' in function getScriptClass,
while it is trying to parse class
 clazz = loader.parseClass(script, generateScriptName());

 generate script name always increments the counter, there is no reference
of getting name from context.
  // generate a unique name for top-level Script classes
    private synchronized String generateScriptName() {
        return "Script" + (++counter) + ".groovy";
    }
Kindly guide.

Thanks
Harish

On Fri, Mar 17, 2017 at 4:48 PM, Edmond Kemokai <ekemokai@gmail.com> wrote:

> Hi Harish,
>
> The <unique number> should be the line number where the problem is. How
> are you setting context that doesn't show file name? The code you're
> running that has the error can't possibly extract something from the
> context since there is an error (I am guessing syntax error?).
>
> I am the developer of HiveMind, it is a JSR223 based web app platform for
> Groovy and other JVM languages. You can access:
>
> url: http://demo.crudzilla.com:7000/
> login: developer/developer
>
> I have created a test file in: /com/crudzilla/cloudTest/web/dewan/test.ste
>
> You can test the code by right clicking on the test.ste file and selecting
> "Open In Browser".
>
> Put your code in there and save, I can review it for you.
>
>
> -Edmond
>
>
> On Fri, Mar 17, 2017 at 6:47 AM, Harish Dewan <harish.dewan@gmail.com>
> wrote:
>
>> Hi All,
>> I am trying to run a groovy script from my Java code using JSR223 and I
>> am using 'groovy-all-2.4.9.jar' .
>> In case of any exception occurring, it gives a generic name as
>> Script<unique number>.groovy , where as the script file name was
>> differently given.
>>
>> I checked for possible solutions, like I need to set the script file name
>> in the context. but the current code for eval does not gets the script file
>> name from context. It creates a unique file name through
>> 'generateScriptName'.
>>
>> Is this a bug or do I need to deal with it differently ?
>> Please guide.
>>
>> Thanks
>> Harish
>>
>>
>
>
>

Mime
View raw message