Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Add message to error stack #2311

Closed
wants to merge 4 commits into from

Conversation

calebmer
Copy link
Contributor

Because of an ordering bug messages weren’t being added to the error stacks thrown by Prepack. This made debugging runtime issues in generated Prepack code difficult.

Input

throw new Error("foo");

Output Before

(function() {
  var $$0 = {
    enumerable: false,
    configurable: true,
    writable: true,
  };

  var _$0 = this;

  var _$1 = _$0.Error;
  var _$2 = _$1.prototype;
  var _$3 = _$0.Object;
  var _$4 = _$3.defineProperty;

  var __constructor = function() {};

  var _0 = ((__constructor.prototype = _$2), new __constructor());

  ($$0.value = "Error\n    at /Users/calebmer/prepack/fb-www/input.js:4:7"), _$4(_0, "stack", $$0);
  ($$0.value = "foo"), _$4(_0, "message", $$0);
  throw _0;
}.call(this));

Output After

(function() {
  var $$0 = {
    enumerable: false,
    configurable: true,
    writable: true,
  };

  var _$0 = this;

  var _$1 = _$0.Error;
  var _$2 = _$1.prototype;
  var _$3 = _$0.Object;
  var _$4 = _$3.defineProperty;

  var __constructor = function() {};

  var _0 = ((__constructor.prototype = _$2), new __constructor());

  ($$0.value = "foo"), _$4(_0, "message", $$0);
  ($$0.value = "Error: foo\n    at /Users/calebmer/prepack/fb-www/input.js:4:7"), _$4(_0, "stack", $$0);
  throw _0;
}.call(this));

Copy link
Contributor

@hermanventer hermanventer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The failing test needs to be addressed.

@@ -150,6 +141,15 @@ export function build(name: string, realm: Realm, inheritError?: boolean = true)
message.throwIfNotConcrete();
}

// Build a text description of the stack.
let stackDesc = {
value: buildStack(realm, O),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

buildStack does not yet handle abstract messages. You can add such support by emitting the stack as a string template. Alternatively, you could just comment out the throw with a TODO comment, along with an issue describing what needs to be done.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Contributor

@hermanventer hermanventer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You still need to fix a Flow error, but other than that it looks good to me.

Copy link

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@calebmer is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@calebmer calebmer deleted the error-stack-message branch July 27, 2018 16:24
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants