macro stacktrace

Because of the JSfication we are getting less feedback when something fails. There is however a nonstandard property .stack on error objects which contains a formatted stacktrace as string. It would be great if we could use it:

Proposed changes to SC:

src/lib/helpers.js: ln 251: change to function throwError(place, message, source, stack) { and after ln 288 add

if (stack) {
	const lines = stack.split('\n');
	for (const ll of lines) {
		const div = document.createElement('div');
		div.append(ll);
		$source.append(div);
	}
}

src/macros/macrocontext.js: ln 275 change to

error(message, source, stack) {
	return throwError(this._output, `<<${this.name}>>: ${message}`, source ? source : this.source, stack);
}

src/macros/macrolib.js: ln 353: change to

return this.error(`bad evaluation: ${typeof ex === 'object' ? `${ex.name}: ${ex.message}` : ex}`, null, ex.stack);

Together with <<print App.UI.DOM.includeDOM(V.building.render(), "buildingDOM")>> (needed because otherwise it's not the print macro that gets the error) the error looks like this:

image

Questions:

  1. Can someone test this in chrome? I only have firefox and ex.stack is nonstandard so I am not sure what will happen (It should work though, according to mdn all browsers have it implemented, there is just no standard for it.

  2. If we use it can someone change the SC patch for it? I got it applied, but I have no idea how to make a new one and what needs to be updated.

  3. We could add it to more macros, any apart from <<set>> and <<run>>?