Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 9EBB9200C3C for ; Mon, 20 Mar 2017 00:56:20 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 9D3DD160B8E; Sun, 19 Mar 2017 23:56:20 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 9D5B7160B7D for ; Mon, 20 Mar 2017 00:56:19 +0100 (CET) Received: (qmail 88637 invoked by uid 500); 19 Mar 2017 23:56:18 -0000 Mailing-List: contact users-help@groovy.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@groovy.apache.org Delivered-To: mailing list users@groovy.apache.org Received: (qmail 88627 invoked by uid 99); 19 Mar 2017 23:56:18 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 19 Mar 2017 23:56:18 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 59B541812F6 for ; Sun, 19 Mar 2017 23:56:18 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.899 X-Spam-Level: * X-Spam-Status: No, score=1.899 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HTML_MESSAGE=2, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_PASS=-0.001, WEIRD_PORT=0.001] autolearn=disabled Authentication-Results: spamd3-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id 62VOjZsdGYBr for ; Sun, 19 Mar 2017 23:56:16 +0000 (UTC) Received: from mail-wr0-f179.google.com (mail-wr0-f179.google.com [209.85.128.179]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTPS id AA1685F341 for ; Sun, 19 Mar 2017 23:56:15 +0000 (UTC) Received: by mail-wr0-f179.google.com with SMTP id g10so82299519wrg.2 for ; Sun, 19 Mar 2017 16:56:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=ViFupCbOt2D5o4qmK7uQxKcRqHMyC7U4uUpUkdPbvrQ=; b=fmsM2yJMf2Rr9oDNd7taETnTSJO8vMVUkY37ekpcokwKUmrztn1F9eRXXf+hKdykuc jhc8slBPSll9iFzue9PTdX8EVrE2ohMqodKT4ZpZVmLVnSCwaMSmGzv/jnAnwhgKmomF zKdD2umiETeygJTbXBlGCDNH1ORFcej8Aem6kEIMEKkJ4p82HNXb/QrcSpqvOg8LjAac hmRra0yDlTLgyRzYM7XxQoJzWCu/eiRYXHPSLKjuYr51jBmy3aIirQ11MafXYEqDMHrQ Oi19xgKgNR3AoFF8+DRzNHonwVxpSr0pvjICNP3W373Jnd0O0Rd3uRhspaYK60xpu65H r7AA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=ViFupCbOt2D5o4qmK7uQxKcRqHMyC7U4uUpUkdPbvrQ=; b=UrPTrDjUDQDUSSLpz5kTKqxcLkU8g9Q/UWhGBbrAFAAojiT3YafJ1nUijDBh6O0UmF p4Hspwtojzhhg4KX5j3pzuOGUpiOAzJjHKrXVTdPYG20BNoNlkYo4J2cpujl4iqeitQv sLzL5xbmjziu/Q45fctfOnYV+XR4okchaFjpH9xLuBVQ0IWhMQsiLHdx6T/eOtlwOocO S7E/gUvEDQekZ0h1gTw69N4qwc7Ovg5w4Cmm6w5aLoNZbGm2acqwVpSG5e0Eilsu6Wkr xDvCsWiswmPK0AIQ+eDUvxEmuXi/cW23AiS4j/TkzhQwhxYtHqs56kOChRzjOOP6kGPW 2QKg== X-Gm-Message-State: AFeK/H2GRbLJyvoarP7APTawvtroIhTNx78cMfo3v8AKEgqtoW8PLFx/kYO62Z4C8XxbzuF2wXn/ZtndpLL6Rw== X-Received: by 10.223.152.215 with SMTP id w81mr25259355wrb.151.1489967775203; Sun, 19 Mar 2017 16:56:15 -0700 (PDT) MIME-Version: 1.0 Received: by 10.28.55.208 with HTTP; Sun, 19 Mar 2017 16:56:14 -0700 (PDT) In-Reply-To: References: From: Edmond Kemokai Date: Sun, 19 Mar 2017 19:56:14 -0400 Message-ID: Subject: Re: ScriptException does not prints actual file name To: users@groovy.apache.org Content-Type: multipart/alternative; boundary=001a113c36a6f7c58d054b1e2717 archived-at: Sun, 19 Mar 2017 23:56:20 -0000 --001a113c36a6f7c58d054b1e2717 Content-Type: text/plain; charset=UTF-8 Hi Harish, You are right, the script name is just a somewhat random identifier. In that case if you really must know the source file that caused the issue and you are executing the groovy code, why don't you capture the resulting exception and perhaps replace the Script.groovy with the name of the file? A simple replace regex can accomplish this. You actually just gave me an idea for improving the error reporting in HiveMind logs :) Regards Edmond On Sun, Mar 19, 2017 at 12:29 PM, Harish Dewan wrote: > 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 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(""); > 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 > wrote: > >> Hi Harish, >> >> The 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/d >> ewan/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 >> 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.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 >>> >>> >> >> >> > --001a113c36a6f7c58d054b1e2717 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi Harish,

You are right, the = script name is just a somewhat random identifier. In that case if you reall= y must know the source file that caused the issue and you are executing the= groovy code, why don't you capture the resulting exception and perhaps= replace the Script<magic number>.groovy with the name of the file? A= simple replace regex can accomplish this.

You actually j= ust gave me an idea for improving the error reporting in HiveMind logs :)

Regards
Edmond

On Sun, Mar 19, 2017 at 12:29 PM, Harish D= ewan <harish.dewan@gmail.com> wrote:
Hi Edmond,
thanks for your = reply.
the unique number which i was talking about is not the lin= e number.=C2=A0
for example: below is an script exception thrown = in case of syntax error.=C2=A0
I had introduced text 'abcd= 9; 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.
<= br>
I was expecting error message of type=C2=A0
javax.s= cript.ScriptException: groovy.lang.MissingPropertyException: No such p= roperty: abcd for class: hello.groovy
=C2=A0
I am setti= ng the context as follows

ScriptEngine engine =3D = new ScriptEngineManager(loader)
.getEng= ineByExtension(extension);
ScriptContext context =3D engine.getContext();
=
context.setAttribute(ScriptEngine.FILENAME, "h= ello.groovy", ScriptContext.ENGINE_SCOPE);

Re= ader r =3D new FileReader("<path to hello.groovy file>");
try
{
engine.eval(r,context);
}
catch (Scrip= tException e)
{
}
I did tried looking into source code and in class 'GroovySc= riptEngineImpl.java' in function getScriptClass,=C2=A0
while = it is trying to parse class=C2=A0
=C2=A0clazz =3D loader.parseCla= ss(script, generateScriptName());
=C2=A0
=C2=A0generate= script name always increments the counter, there is no reference of gettin= g name from context.
=C2=A0 // generate a unique name for top-lev= el Script classes
=C2=A0 =C2=A0 private synchronized String gener= ateScriptName() {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 return "Script= " + (++counter) + ".groovy";
=C2=A0 =C2=A0 }
=
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 numbe= r where the problem is. How are you setting context that doesn't show f= ile 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/develope= r

I have created a test file in: /com/crudzilla/clou= dTest/web/dewan/test.ste

You can test the code by ri= ght clicking on the test.ste file and selecting "Open In Browser"= .

Put your code in there and save, I can revie= w it for you.


-Edmond


On Fri, Mar 17, 2017 at 6:47 AM, Harish De= wan <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, i= t gives a generic name as Script<unique number>.groovy , where as the= script file name was differently given.

I checked for possible soluti= ons, like I need to set the script file name in the context. but the curren= t code for eval does not gets the script file name from context. It creates= a unique file name through 'generateScriptName'.

Is t= his a bug or do I need to deal with it differently ?=C2=A0
Please guide= .

Thanks=C2=A0
Harish

=



=



--001a113c36a6f7c58d054b1e2717--