BaseXException

Thursday, 9 December 2010 · 5 messages
MB
Mark Boon9 Dec 2010 05:15 #
This is a bit an off-the-wall request but I figured it doesn't hurt to throw out here as an idea. When I have an error in my query I typically get a BaseXException saying something like: org.basex.core.BaseXException: Stopped at line 42, column 55: [XPST0003] Expecting ")", found """. However, it doesn't show me the query. Since I generate (sometimes large) queries automatically, this message by itself is not always very helpful (to put it very mildly). Either I print all my queries in their entirety, something that results in a dazzling amount of output. Or I jump through some hoops and try to keep my last query so it can be printed alongside the exception. Both are not very satisfactory solutions. I was thinking though how nice it would be if the exception could print the query for me. And the icing on the cake would be if (in the above example) it would print an extra line just after line 42 with 54 spaces and ^ at column 55, so I get an arrow pointing out where the error is without me having to count to 42 first and then to 55. Whatcha all think? Personally, I think it's such a good idea I was thinking of doing it myself. If the BaseX6.3 source were available, that is. Mark Boon
JC
Jan Vlčinský (CAD)9 Dec 2010 10:02 #
Hi Mark I would be a bit concerned about printing entire XQuery as I use it often over Internet and including possibly large XQuery text the message could be dangerous. In your code, you have probably the xquery just one or two lines above the place, the code have thrown the exception. You may let your catch code to print the XQuery on your own, without forcing BaseX to do it for you. Printing thee lines of XQuery would be perfectly fine. Just my point of view. Jan
Quoted text · Mark Boon · 35 lines
On Thu, Dec 9, 2010 at 4:15 AM, Mark Boon <mboon at avatar-reality.com> wrote: > This is a bit an off-the-wall request but I figured it doesn't hurt to > throw out here as an idea. > > When I have an error in my query I typically get a BaseXException > saying something like: > > org.basex.core.BaseXException: Stopped at line 42, column 55: > [XPST0003] Expecting ")", found """. > > However, it doesn't show me the query. Since I generate (sometimes > large) queries automatically, this message by itself is not always > very helpful (to put it very mildly). Either I print all my queries in > their entirety, something that results in a dazzling amount of output. > Or I jump through some hoops and try to keep my last query so it can > be printed alongside the exception. Both are not very satisfactory > solutions. > > I was thinking though how nice it would be if the exception could > print the query for me. And the icing on the cake would be if (in the > above example) it would print an extra line just after line 42 with 54 > spaces and ^ at column 55, so I get an arrow pointing out where the > error is without me having to count to 42 first and then to 55. > > Whatcha all think? > > Personally, I think it's such a good idea I was thinking of doing it > myself. If the BaseX6.3 source were available, that is. > > Mark Boon > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >
-- *Ing. Jan Vlčinský* CAD programy Slunečnicová 338/3, 734 01 Karviná Ráj, Czech Republic tel: +420-597 602 024; mob: +420-608 979 040 skype: janvlcinsky; GoogleTalk: jan.vlcinsky at gmail.com http://cz.linkedin.com/in/vlcinsky
CG
Christian Grünin reply to Mark Boon, 9 Dec 2010, 05:159 Dec 2010 12:08 #
Quoted text · Mark Boon · 6 lines
> org.basex.core.BaseXException: Stopped at line 42, column 55: > [XPST0003] Expecting ")", found """. > > However, it doesn't show me the query. Since I generate (sometimes > large) queries automatically, this message by itself is not always > very helpful (to put it very mildly).
In your case, I'd recommend to wrap query execution with try/catch and lookup the relevant snippet by yourself; this is similar to what Jan has already proposed. If this should not be possible for reason, feel free to comment back on this. Based on my experiences, a more detailed error feedback would represent undesirable overhead. Christian
MB
Mark Boon9 Dec 2010 21:10 #
Well, as I said, it was just an off-the-wall idea. And I appreciate the focus on performance, it's paramount. Having said that, the XQuery class is the one that has the query and generates the exception and is thereby in the unique position to easily perform certain services, like providing a nicely formatted error to the exception. Any other solution is going to be a workaround at best. The best I can think of right now is to sub-class XQuery and catch the BaseXException and wrap it in a new exception in the execute() method and add a printErrorDetail() method that does the formatting as I explained. I see little drawback in terms of either performance or security, as you'll still be free to use the base-class in any case. So that's what I'll do. Maybe I'm the only one who sees the value of it, I thought there would be more developers who'd benefit of such an implementation. Mark
Quoted text · Christian Grün · 19 lines
On Thu, Dec 9, 2010 at 1:08 AM, Christian Grün <christian.gruen at gmail.com> wrote: >> org.basex.core.BaseXException: Stopped at line 42, column 55: >> [XPST0003] Expecting ")", found """. >> >> However, it doesn't show me the query. Since I generate (sometimes >> large) queries automatically, this message by itself is not always >> very helpful (to put it very mildly). > > In your case, I'd recommend to wrap query execution with try/catch and > lookup the relevant snippet by yourself; this is similar to what Jan > has already proposed. If this should not be possible for reason, feel > free to comment back on this. > > Based on my experiences, a more detailed error feedback would > represent undesirable overhead. > > Christian >
MB
Mark Boon9 Dec 2010 21:10 #
Rats, I just found out that the XQuery class is defined as final. :-((
Quoted text · Mark Boon · 42 lines
On Thu, Dec 9, 2010 at 8:40 AM, Mark Boon <mboon at avatar-reality.com> wrote: > Well, as I said, it was just an off-the-wall idea. And I appreciate > the focus on performance, it's paramount. > > Having said that, the XQuery class is the one that has the query and > generates the exception and is thereby in the unique position to > easily perform certain services, like providing a nicely formatted > error to the exception. Any other solution is going to be a workaround > at best. The best I can think of right now is to sub-class XQuery and > catch the BaseXException and wrap it in a new exception in the > execute() method and add a printErrorDetail() method that does the > formatting as I explained. I see little drawback in terms of either > performance or security, as you'll still be free to use the base-class > in any case. > > So that's what I'll do. Maybe I'm the only one who sees the value of > it, I thought there would be more developers who'd benefit of such an > implementation. > > Mark > > > On Thu, Dec 9, 2010 at 1:08 AM, Christian Grün > <christian.gruen at gmail.com> wrote: >>> org.basex.core.BaseXException: Stopped at line 42, column 55: >>> [XPST0003] Expecting ")", found """. >>> >>> However, it doesn't show me the query. Since I generate (sometimes >>> large) queries automatically, this message by itself is not always >>> very helpful (to put it very mildly). >> >> In your case, I'd recommend to wrap query execution with try/catch and >> lookup the relevant snippet by yourself; this is similar to what Jan >> has already proposed. If this should not be possible for reason, feel >> free to comment back on this. >> >> Based on my experiences, a more detailed error feedback would >> represent undesirable overhead. >> >> Christian >> >

⚡Generated with XQuery