[SOLVED] Custom exception/error not show text info in browser console [html5]

All exceptions which thrown like this

throw "text error";

or this

throw new Error("object error");

has no text info in the console output.

Firefox (37) writes just “Error:” without any text and even without any information about codeline in the source from where exception is thrown. Opera (29) also writes no text, but gives me info about codeline so I can look where is actually that errors happened.

Haxe 3.2-rc2, Lime 2.3.3, OpenFl 3.0.3
.

What the reason? It is my browsers/OS (I use WinXP) problem? Or the problem with Lime or even with Haxe ?

What is the actual JavaScript code being executed, when it brings you to the location? I’m curious how Haxe is translating “throw” to JS

Haxe

public function new() 
    {
        super();
        
        throw new Error("just error");
        throw "another error";
    }

js output

var Main = function() {
    openfl_display_Sprite.call(this);
    throw new js__$Boot_HaxeError(new openfl_errors_Error("just error"));
    throw new js__$Boot_HaxeError("another error");
};

Hey, great news.

I dug into this and almost had a solution, when I realized that the Haxe Boot class for JS was updated with a patch for this very thing. I’ve just committed it to Lime.

Are you using Lime from the source? If not, try replacing the “lime/js/Boot.hx” file with the contents of the one I just committed, and try again :slight_smile:

I just copied new constructor code and now I see the text info. COOL!

Also I can note that for any type of custom error (throw new ArgumentError() or throw new IOError()) type of the error is always Error, e.g.

var a:Sprite = null;
//  Uncaught TypeError: Cannot read property 'set_alpha' of null
a.alpha = 4;   

//  Uncaught Error: just error
throw new ArgumentError("just error");   

But it is not a problem since I can see the text messages, thanks!

It might be possible to set the name property within the Haxe Boot class in order for it to print differently, although when I try the following code:

throw new ArgumentError ("Oh no!");

I get “Uncaught Oh no!” or “uncaught exception: Oh no!” in Opera, Chrome or Firefox, so not even “Error”

I’m not sure why I don’t see the name (what browser are you using?) but actually, we might be able to improve this by setting the name value in the custom Error classes.

Could you try adding this to your copy of openfl.errors.ArgumentError, and do you have any idea why I don’t see the name in my console errors?

name = "ArgumentError";

Firefox 37.0.2, Opera 29.0.1795.30, Chrome 42.0.2311.135 m. And I see the default name “Error”. Changing the name does not make any sense now, because the HaxeError class does nothing with name property. So is need to check the type (String or Error) and read the name property if val param is openfl Error object.

Current solution can be like this

public function new(val:Dynamic) untyped {
        super();
        this.val = __define_feature__("js.Boot.HaxeError", val);
        if (Std.is(val, openfl.errors.Error)) {
            var error:openfl.errors.Error = cast val;
            this.name = error.name;
            this.message = error.message;
        }
        else {
            // it should fix no "Error" text for singmajesty
            this.name = "Error";
            this.message = String(val);
        }
        if (js.Error.captureStackTrace) js.Error.captureStackTrace(this, HaxeError);
    }

Also is steel need to set name property for error subclasses - manually for each of them like sample with ArgumentError, or do this in Error class:

class Error {
    public function new (message:String = "", id:Int = 0) {
        
        name = StringTools.replace(Type.getClassName(Type.getClass(this)), 'openfl.errors.', "");
        
    }
}

That works but looks a little terrible :smile:

Perhaps we should hard-code name properties for each standard Error, or yeah, the Type.getClassName is probably a good universal solution, perhaps as a getter. I see what you mean, though, we still need to set the name in the haxe error call

Thanks! It’s working for me now

I just committed an improvement to Lime with the js.Boot that looks for a “name” or “message” field on the error value, if these exist, it will use those, otherwise it uses the standard “Error” and Std.string for the value

I also added name properties for the OpenFL error classes, so now we get a proper “Uncaught ArgumentError: AAUUGH!!!” like you get in Flash :wink:

I see the changes, nice!