Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Control flow with exceptions #6754

Closed
ncannasse opened this issue Nov 24, 2017 · 7 comments
Closed

Control flow with exceptions #6754

ncannasse opened this issue Nov 24, 2017 · 7 comments

Comments

@ncannasse
Copy link
Member

ncannasse commented Nov 24, 2017

It is a often used principle in FP to use exceptions for control flow.
These exceptions can hold complex values that should not be stringified (they might have recursive values loops)

Or I noticed that's exactly what js.HaxeError does.... it Std.string the exception value when the exception is created...

Could this be avoided ?

I had to change hscript implementation that was throwing exception in the form or throw SReturn(value) because of the bugs it produces.

Maybe the recent PR #6713 also causes some regression here, by using Std.string instead of String(value) ping @nadako

@nadako
Copy link
Member

nadako commented Nov 24, 2017

Hmm, it shouldn't use Std.string, and I believe most JS engines have protection against recursion loops when stringifying values. Also I think even Std.string have protection against too many levels of recursion, no?

What exactly is the issue there?

@ncannasse
Copy link
Member Author

I had a stack overflow error when returning a complex expression in hscript. I fixed it with HaxeFoundation/hscript@8c04831
It involved a StringMap.toString() which itself was calling Std.string

@ncannasse
Copy link
Member Author

Try running the following on Node:

class Main  {

	static function main() {
		try {
			var m = new Map<String,Dynamic>();
			m.set("recurse",m);
			throw m;
		} catch( e : String ) {
			trace("CAUGHT string ?");
		}
	}

}

it seems String(m) triggers m.toString()

@nadako
Copy link
Member

nadako commented Nov 25, 2017

Right, custom toString... The problem here is that we want to fill some message for thrown errors or they'll be incomprehensible and doing String(val) sounds like the best thing we can do. Gotta think about it, but right now I'm thinking that maybe it's more of a Map issue.

@ncannasse
Copy link
Member Author

ncannasse commented Nov 25, 2017 via email

@nadako
Copy link
Member

nadako commented Nov 25, 2017

There should be some way, toString or maybe a js getter for the message property, gotta look into it...

@ncannasse
Copy link
Member Author

ncannasse commented Nov 26, 2017 via email

@nadako nadako closed this as completed in 2402c58 Nov 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants