Getting source code information from groovy stack trace - grails

When exception generated I want to show some additional information (source code) for particular exception. But grails have very hairy exceptions (it's all about groovy dynamic nature). It's my problem where to get and how to display source code. All I need is file/line information.
So... Is there any possibility to get file and line where exception were generated in grails/groovy?

Hmm, you aren't already getting this? All my grails exceptions have file/line information in them by default. The only difficulty is that if the exception is in a closure, it doesn't show the actual closure name. Could you post a sample stacktrace?

Related

Special case: wrong order of updates for fly-away

How can I track down the location of the "Special case: wrong order of updates for fly-away!" error?
This error message is defined in Datasnap.DSIntf as
const
...
ERRCODE_FLYAWAY_WRONGORDER = 13; { Special case: wrong order of updates for fly-away }
...
DBERR_FLYAWAY_WRONGORDER = ERRBASE_ALC + ERRCODE_FLYAWAY_WRONGORDER;
but nowhere else in the Delphi sources can I find references to substring FLYAWAY_WRONGORDER.*
My intention was to compile with debug dcu's, then put a breakpoint on the line where the exception is raised and check the call stack UP to find the cause.
I'm currently stepping DOWN into the code until the error occurs, but that is less efficient (complex app).
Placing a TApplicationEvents with a breakpoint in its OnException handler does not give me usable call stack information:
So, how can I (efficiently) track down the place where this error is generated?
Background on what is going on:
Form uses DevExpress TcxScheduler connected to TcxSchedulerStorage component in datamodule, connected to nested TClientDataSets
Code saves all changes to these datasets (ApplyUpdates)
In BeginUpdate/EndUpdate for these DevExpress components, I then insert, delete and update records in these datasets, move around while doing so, even change parent IDs in detail datasets so that they drop from the current detail dataset 'in view'.The error occurs when I Edit, then Post a record doing exactly that.
Delphi Tokyo 10.2.3, Win32 app
Any other info on that error message is welcome, I was not able to find anything.
I actually 'fixed' the error by calling ApplyUpdates for the master dataset in a few places, but since I'm not really sure about the cause I want to investigate this further. So my question is not How do I fix the error in my code, it is How do I find the error in my code?
* There is a CheckForFlyAway routine in TCustomADODataSet.InternalPost in Data.Win.ADODB but we don't use ADO, I cannot set breakpoints in those routines.

Get error information if luaL_loadfile fails

If luaL_load function fails, then, according to the documentation (Lua5.1), the error message is pushed on the stack and can be retrieved with lua_tostring(L, -1), but if I want to print a customized error message, I don't think I can use lua_Debug (because that is for active function). Is there any other way (other than parsing the string) to get the file, line number and what error occured ?
--
Thanks.
The error code returned by luaL_loadfile tells you what kind of error happened. You're mostly likely only interested in LUA_ERRSYNTAX, in which case there is a detailed error message left on the stack. This is the only record of the error. If you need to reformat it, you need to parse it.
During a luaL_load(), there is nothing techinally on the stack that is relavant to the loading of the script. No functions are performed or executed in the script. Its just a compilation step, returning a function that encapsulates the whole file or the error found during compilation.
If you get a function back, you execute this to actually run the script, which sounds like what you are really interested in. In which case you can use a lua_pcall() and provide an error handler. In your handler you would then have your expected stack trace available via lua_Debug.

class EVariantTypeCastError with message 'Could not convert variant of type (String) into type (Double)

Using Delphi and FastReport I get this error message while debugging inside Delphi immediately after this line:
<FastReport_Component>.ShowReport(true);
Then this error appear:
Project myapp.exe raised exception class EVariantTypeCastError with message 'Could not convert variant of type
(String) into type (Double)'.
It appears twice before displaying the report. but if I run myapp without debugging no error message appear.
How I can find which memo cause this error ? the report has so many memos. some has also expressions inside using IIF and the error message does not display any more info.
This is just the debugger. It's probably just getting an expected error (one handled by a try..except in the FR code) and properly dealing with it, but the debugger has no way of knowing that and tells you the exception happened. (It's a common issue when working with Indy, which raises exceptions as part of normal program flow.)
There are three ways to deal with this situation when debugging:
Just hit Continue on the exception dialog when it appears. (You can tell it's a debugger exception because you get the Break or Continue option, and because it only happens when debugging.)
You can disable a specific exception class (or all exceptions) when debugging, using the Tools->Options->Debugger Options. In this case, you can add EVariantTypeCastError to the list of exceptions to ignore.
(My preferred method) Use the Advanced Breakpoint Properties dialog to skip the debugger's exception handling around the specific line of code you know will raise the exception you want to ignore.
Set a breakpoint on the line immediately before the problem code line.
Right-click the breakpoint on the line before, and choose Breakpoint Properties from the context menu.
Click the Advanced button on the Breakpoint Properties dialog, and in the Actions groupbox, uncheck Break and check Ignore subsequent exceptions.
Repeat the previous steps on the line after the problem code, except check Break and uncheck Ignore subsequent exceptions on this second breakpoint.
Run your code as usual. The debugger will skip it's exception handling on the code between the two breakpoints.
The advantage of option #3 is that it ignores all exception handling, but only on the code block between the two breakpoints, so you still get exceptions in all other areas of your code that may be valid exceptions in the debugger.
I got this exact same error but not with FastReport. I'll leave the context of my error, as it may help someone else. I got this error on:
RESTRequest.Execute();
I was using the TClientDataSet with TRESTResponseDataSetAdapter so that after a request to my web service the adapter would load a data set with the JSON string returned by the web service. This data set was being used to automatically check/uncheck checkboxes and load textedits and comboboxes. Since TJSONObject does not parse booleans correctly in json, I changed some checkboxes to check/uncheck based on an integer value instead of a boolean. I was then changing my webservice so that it looks for boolean columns in the datatable to an integer value 1 or 0. For some reason (my fault entirely), I was outputting a json with "" in that field instead of the integer ("1" or "0"). And this yielded that exact error. After correcting this, the error disappeared.
I had a similar issue in FastReport. In my case, it was a wrong Format applied to a MemoView. I could find the name of the offending component this way:
Use Break to stop the execution
In the Call Stack panel, find the latest call from a fastreport class (in my case: frxClass.TfrxCustomMemoView.FormatData(...) and double click it.
if you don't have the source code od Fast Report, a dialog appears - just hit Cancel
in Local Variables panel, you will probably see name of the offending component / value / format.

Delphi exceptions not letting me see local variables

When debugging in Delphi, an exception will correctly tell me the line of code causing the fault, but I cannot get access to any local variables. Is this a limitation in the debugger? Or am I missing something simple? At present, I have to mirror all local variables to a global on the line before the fault, recompile the program and hope to be able to repeat the same exception.
For example
MyArray[I]:=Foo(...);
If I is out of bounds (with bounds checking turned on), I cannot see what the variable I is, unless I mirrored it to a globally scoped debug variable on the previous line.
Or if I have
MyInteger:=Trunc(MyFloat),
and MyFloat is 6.1E+17, I have no idea what it's value is.
You can see the values of local variables when you select the proper line in the call stack window. It is usually one or two lines before the exception is raised.
I don't have the exact version at hand when this has been implemented, but it is definitely one of the newer versions.
The "problem" is caused by the compiler as far as I know. The optimization feature of the compiler acts like a garbage collector, it frees the variables declared within a function when not used any more.
To overcome the problem, write a exception handler and make a fake use of the variable within the exception catch block.

Is it possible to have an aspect around other aspects

my question is related to this question
We have different aspect class that do #around advice on different part of an application (fat client in Swing) to measure the execution time.
I have another aspect (ExceptionHandler) that do #around on all the aspects method i wrote.
I did this to avoid that the aspects created would throw exception and make the client application fails. So basically, i try catch the Proceed of my other #around method and just log exception that arise. I only throw an exception when i detect it come from the proceedingJoinPoint
if (joinPoint.getSignature().getDeclaringTypeName().equalsIgnoreCase("org.aspectj.lang.ProceedingJoinPoint")) {
throw exception;
}
Is it valid to do this?
In Eclipse with AJDT the app run fine and i tested the ExceptionHandler and it worked as expected.
But in other env. (Integration) the application fail as soon as it meet a line advised by the exceptionHandler with this Error
Exception in thread "main" java.lang.NoSuchMethodError: com.xxx.yyy.aop.aspect.ExceptionHandlerAspect.aspect
Of()Lcom/xxx/yyy/aop/aspect/ExceptionHandlerAspect;
at com.xxx.yyy.aop.aspect.ecs.AspectBaseEcs.inspectLoginInfo(AspectBaseEcs.java:65)
at com.xxx.yyy.app.es.security.Security.loadApplications(Security.java:172)
at com.xxx.yyy.app.es.gui.VSDlgLogin.loadSecurity(VSDlgLogin.java:346)
at com.xxx.yyy.app.es.ApplicationSuite.start(ApplicationSuite.java:839)
at com.xxx.yyy.app.es.ApplicationSuite.main(ApplicationSuite.java:501)
I have also decompile the code to see if aspectOf() was weaved into my ExceptionHandler and the method is there!!!!!!!???????????
Why this error rise...?
I'm clueless.
Finally found the problem. Our Application had a dependency on common module jar that was containing aspect too.
The base package name was the same : com.xxx.aop and the base class we used for our aspects was the same name!!!! So 2 com.xxx.aop.AspectBase.class were loaded.
Since we used a flag in our ant build file to enable compile time weaving at yes/no, one of our AspectBase.class was not weaved while the other was.
Can't believe i didn't see that before!!!!!

Resources