Debugging Neko web server

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Debugging Neko web server

bubblebenj
Hi,

I wonder if I'm missing the right way to debug Neko server.
Here's an example of bug that is hard to debug despite the fact it's a simple problem :

I'm running a neko web server that interact with flash via a proxy.
Everything compile fine, but at execution time at got this message send from the server to my flash client
"Class cast error".
Since I output a message on console via neko.Web.logMessage almost each time I enter a function on the server I should be able to find my problem easily.

I should but it not the case since the server is asynchronous, the message could actually be about a function called a while ago.

So I've got 2 problems :
1 - The message being vague. Neither I know which function executed this code, neither I know the type that the program is trying to cast.
2 - I really wish there were a similar function as the js.Lib.setErrorHandler on the Neko target thus a can redirect myself message error. Maybe it exists already but i didn't find it.

Any suggestion, method for this kind of problem would be of great help

Ben

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Debugging Neko web server

MarcWeber
compile with -debug flag.
Then you get kind of stack trace?

This should tell you where the cast is missing.

You could also try compiling to PHP and use xdebug..
However then the behaviour could change.

Marc Weber

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Debugging Neko web server

bubblebenj
Thanks for the reply, but -debug flag was enabled already.

I found a way I'll share for those interested in :

the first thing is to use the try/catch thing except that putting that in every function will make the code very messy. I've tried to put it in the main but it doesn't seem to work anyway the solution is to put the try / catch in each API function like that :
public function myAPIfunc( _Arg1: MyType ) : Int
{
try
{
// API code here
}
catch ( _Error : Dynamic )
{
MyDebugClass.ERRORMSG( _Error );
return null;
}
}

Then the code in MyDebugClass.ERRORMSG is :
public static function ERRORMSG( _Error : Dynamic, ?pos : haxe.PosInfos  )
{
neko.Web.logMessage( pos.fileName + ":" + pos.lineNumber +
" : ERROR \"" + _Error + "\" " + haxe.Stack.toString( haxe.Stack.exceptionStack() );
}

And it display something like this :
[log] My_Server.hx:213 : ERROR "Class cast error"
Called from packageA.ClassB::MyBuggingFunction line 76
Called from packageA.ClassA::AFunction line 83
Called from My_Server::myAPIfunc line 209

It is verbose enough to debug. The only drawback is having to do a try / catch in each api function. It's acceptable but if someone knows a better way I'm all ears.

Ben

On Sat, May 28, 2011 at 11:58 AM, Marc Weber <[hidden email]> wrote:
compile with -debug flag.
Then you get kind of stack trace?

This should tell you where the cast is missing.

You could also try compiling to PHP and use xdebug..
However then the behaviour could change.

Marc Weber

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Debugging Neko web server

MarcWeber
Eventually macros could be used to create those try .. catch blocks.

In Ruby or Python you can "monkey patch" such things. I'm not sure
whether neko does allow doing that in some way.

Monkey patching means that you dynamically change the behaviour of code
such as:


class.method = function(){
  // create reference to old method:
  var f = class.method;
 
  return function(){
    try
      f(arguments)
    catch {..}
  }
}();

Marc Weber

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Debugging Neko web server

Nicolas Cannasse
In reply to this post by bubblebenj
Le 29/05/2011 10:55, benjamin Dubois a écrit :
> Thanks for the reply, but -debug flag was enabled already.
>
> I found a way I'll share for those interested in :
>
> the first thing is to use the try/catch thing except that putting that
> in every function will make the code very messy. I've tried to put it in
> the main but it doesn't seem to work anyway the solution is to put the
> try / catch in each API function like that :

When you mean "API" functions, I guess you mean that you're using a neko
remoting server ? In that case, you will have a default onError handler
on ThreadServer that will print things on stderr. You can redefine it to
use logMessage instead.

Nicolas

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Debugging Neko web server

bubblebenj
Well, you may call me monsieur Jourdain and I may use ThreadServer but I don't think I'm using it.

What I know is that I use a Neko server with a haxe.remoting.HttpConnection.
What I called API functions are not haxe API's, sorry to have make it confusing.
I meant the functions created on the server called by the client (a flash one i this case) via a(n async)proxy.

Ben

On Sun, May 29, 2011 at 6:42 PM, Nicolas Cannasse <[hidden email]> wrote:
Le 29/05/2011 10:55, benjamin Dubois a écrit :

Thanks for the reply, but -debug flag was enabled already.

I found a way I'll share for those interested in :

the first thing is to use the try/catch thing except that putting that
in every function will make the code very messy. I've tried to put it in
the main but it doesn't seem to work anyway the solution is to put the
try / catch in each API function like that :

When you mean "API" functions, I guess you mean that you're using a neko remoting server ? In that case, you will have a default onError handler on ThreadServer that will print things on stderr. You can redefine it to use logMessage instead.

Nicolas

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org