-
Notifications
You must be signed in to change notification settings - Fork 75
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
feat(ses): Carry compartment names in error messages #431
Conversation
packages/ses/NEWS.md
Outdated
* No changes yet. | ||
* Adds the `name` option to the `Compartment` constructor and `name` accessor | ||
to the `Compartment` prototype. | ||
Errors that pass through a compartment may be annotated with the compartment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From reading this description I was confused about what to expect.
- These are only errors that happen during load. What about errors raised by user code during module initialization?
- By "annotated" you do not mean that you mutate the error object in place. (Whew!) Rather you rethrow a new error object that is like the old one except for added text in the message string.
packages/ses/src/compartment-shim.js
Outdated
@@ -204,6 +209,7 @@ export const makeCompartmentConstructor = (intrinsics, nativeBrander) => { | |||
function Compartment(endowments = {}, moduleMap = {}, options = {}) { | |||
// Extract options, and shallow-clone transforms. | |||
const { | |||
name = '<unknown>', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe <unnamed>
?
packages/ses/src/module-load.js
Outdated
moduleSpecifier, | ||
).catch(error => { | ||
const { name } = compartmentPrivateFields.get(compartment); | ||
throw new Error( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given
we should reproduce the error class as well
throw new Error( | |
const ErrorConstructor = NativeErrors[error.name] || Error; | |
throw new ErrorConstructor( |
Rather than importing NativeErrors
from tame-error-constructor.js, it should go in whitelist.js. But that does not need to happen in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given the recursion, is the intent that each level of recursion adds its own location info?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem with reconstructing the error object is that you silently lose the call stack associated with the original error object. What assumptions are you making about ambient availability of a console
object for this code? Nothing I've done for keeping track of error stack correspondence is close to ready. One thing this code can do in the meantime is to do something like
const newError = NewErrorContructor(...);
if (someAppropriateOption) {
console.log(error, 'rethrown as', newError);
}
throw newError;
The normal console behavior is to emit the stacks associated with error objects it logs. This would at least give us the correspondences to grovel through to find the original error stack.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Depending on your goals and your console
assumptions, we could take the opposite approach:
if (someAppropriateOption) {
console.log(error, `, loading ${q(moduleSpecifier)} in compartment ${q(name,)}`);
}
throw error;
This completely avoids recreating new error objects as well as modifying the thrown one in place. It rethrows the one we've got, which retains the stack trace it was constructed with. All the new compartment-name diagnostic info in only logged to the console
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it suffice to reüse the error.constructor
?
3a12559
to
68f2852
Compare
677a949
to
e94fbe4
Compare
e140f2c
to
ec31d51
Compare
128b630
to
5fb3910
Compare
4f9b18a
to
cf22857
Compare
9e9c09b
to
fd6c1b6
Compare
cf22857
to
abc3697
Compare
fd6c1b6
to
f03e404
Compare
abc3697
to
ef542c7
Compare
f03e404
to
ad8d6a2
Compare
ef542c7
to
2506747
Compare
ad8d6a2
to
89883e1
Compare
2506747
to
2bdad74
Compare
2bdad74
to
aa7871e
Compare
This change adds the
name
option to theCompartment
constructor, aname
accessor to theCompartment
prototype, and annotates certain errors that pass through theCompartment
with the name of the compartment they pass through.