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

Combine error taming, rich assert, and console virtualization #447

Merged
merged 2 commits into from
Oct 12, 2020

Conversation

erights
Copy link
Contributor

@erights erights commented Sep 2, 2020

Fixes #440

@erights erights requested a review from kriskowal September 2, 2020 01:10
Copy link
Member

@kriskowal kriskowal left a comment

Choose a reason for hiding this comment

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

This looks like it’s starting well.

We will have to come up with a sensible way to use console as a shim vs assert as a module. There’s a tension there. It might be good to separate the layers such that assert is a module that relies on the underlying console for reporting.

Also, console implementations do generally implement sprintf style log methods. We probably can and ought to respect those as valid ways to pronounce details.

package.json Outdated Show resolved Hide resolved
packages/console/.prettierrc.json Outdated Show resolved Hide resolved
@erights erights force-pushed the console branch 2 times, most recently from 8d1e8d2 to 7fc7429 Compare September 3, 2020 03:37
@erights erights changed the title WIP combining error taming, rich assert, and console virtualization Combine error taming, rich assert, and console virtualization Sep 3, 2020
@erights erights marked this pull request as ready for review September 3, 2020 03:39
@erights
Copy link
Contributor Author

erights commented Sep 3, 2020

Hi @kriskowal this is ready for review. However, in getting here, this got rather large. If you'd like, we should discuss how to break it up into reviewable-sized chunks.

@erights erights force-pushed the console branch 4 times, most recently from 5a8fe20 to 97c7c3a Compare September 7, 2020 22:10
Copy link
Member

@kriskowal kriskowal left a comment

Choose a reason for hiding this comment

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

This is a partial review. I am still digesting.

packages/console/src/assert.js Outdated Show resolved Hide resolved
packages/assert/src/main.js Outdated Show resolved Hide resolved
packages/console/package.json Outdated Show resolved Hide resolved
packages/console/package.json Outdated Show resolved Hide resolved
packages/console/src/console.js Outdated Show resolved Hide resolved
packages/console/test/throwsAndLogs.js Outdated Show resolved Hide resolved
@kriskowal
Copy link
Member

This is a partial review. I am still digesting.

Capturing out-of-band feedback: I’m recommending that we use an API like

} catch (error) {
  assert.note(error, details`number too small ${num}`);
  throw error;
}

(Which I believe would be more palatable than logToConsole(...asLogRecord(...)))

Recommending that we use the catch-and-rethrow in SES module loading as a proving ground for this, and as an example of usage in this change.

I retract my suggestion that we use the term cause (in favor of using note), since I believe there’s a separate need for that term for in-band error annotation, e.g., new Error('Could not find spoon', networkErrorThatCausedFailureToFindSpoon), where code can catch and programmatically inspect the cause chain to make relevant recovery decisions (like whether to retry).

@kriskowal
Copy link
Member

I’m intrigued by the idea that the assertion library would provide “progressively enhanced” behavior depending on whether the console in scope is tamed or untamed. On the one hand, emitting the annotations to the debug system is good. On the other hand, reporting them to the untamed console, regardless of whether they’re later recovered, is a nightmare developer experience.

I will look more closely at this change. I suspect that the untamed case would need a mechanism for correlating related log messages, perhaps using a sequential identifier.

@erights
Copy link
Contributor Author

erights commented Sep 9, 2020

Ready for review!

@erights erights requested a review from warner September 10, 2020 18:06
@erights
Copy link
Contributor Author

erights commented Sep 10, 2020

Adding @warner and leaving @michaelfig as optional reviewers. Only review from @kriskowal is critical.

@erights
Copy link
Contributor Author

erights commented Sep 10, 2020

This is a partial review. I am still digesting.

Capturing out-of-band feedback: I’m recommending that we use an API like

} catch (error) {
  assert.note(error, details`number too small ${num}`);
  throw error;
}

(Which I believe would be more palatable than logToConsole(...asLogRecord(...)))

Done.

Recommending that we use the catch-and-rethrow in SES module loading as a proving ground for this, and as an example of usage in this change.

Still TODO. After this PR is merged but before integration?

I retract my suggestion that we use the term cause (in favor of using note), since I believe there’s a separate need for that term for in-band error annotation, e.g., new Error('Could not find spoon', networkErrorThatCausedFailureToFindSpoon), where code can catch and programmatically inspect the cause chain to make relevant recovery decisions (like whether to retry).

Done.

Copy link
Member

@kriskowal kriskowal left a comment

Choose a reason for hiding this comment

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

I would like to at least discuss the proposed console API extension. Apart from that, all remaining feedback is for your discretion.

packages/console/test/throws-and-logs.js Outdated Show resolved Hide resolved
packages/console/test/throws-and-logs.js Outdated Show resolved Hide resolved
packages/assert/src/assert.js Outdated Show resolved Hide resolved
packages/assert/src/assert.js Outdated Show resolved Hide resolved
packages/assert/src/main.js Outdated Show resolved Hide resolved
packages/console/test/throws-and-logs.js Outdated Show resolved Hide resolved
packages/ses/package.json Outdated Show resolved Hide resolved
packages/ses/src/evaluate.js Outdated Show resolved Hide resolved
packages/ses/src/scope-handler.js Outdated Show resolved Hide resolved
packages/ses/src/lockdown-shim.js Show resolved Hide resolved
Copy link
Member

@michaelfig michaelfig left a comment

Choose a reason for hiding this comment

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

I looked carefully at the types, and from that standpoint, LGTM!

@erights
Copy link
Contributor Author

erights commented Sep 27, 2020

Ready for review again. For assert.js and console.js, I recommend reviewing the whole files rather than the diffs.

@erights
Copy link
Contributor Author

erights commented Sep 27, 2020

For assert.js and console.js, I recommend reviewing the whole files rather than the diffs.

Nevermind. I squashed and both modules are new compared to master, leaving little choice but to compare entire files. My apologies; I should have squashed less aggressively.

Copy link
Member

@kriskowal kriskowal left a comment

Choose a reason for hiding this comment

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

Thank you for working in my feedback on the API. This seems better.

I am still concerned about the special relationship between assert and console. The console gets constructed with view into a particular assert module instance, but I expect each compartment will have its own assert module instance and errors will be forwarded only to the root console.

How do we ensure that details attached in a deeply nested compartment surface to the outermost console?

packages/ses/test/tame-console.test.js Outdated Show resolved Hide resolved
packages/ses/test/tame-console.test.js Outdated Show resolved Hide resolved
@erights erights marked this pull request as draft September 28, 2020 18:37
@erights
Copy link
Contributor Author

erights commented Sep 28, 2020

Back to draft until it is again ready for review. Please spend no more time reviewing the current state.

@erights erights force-pushed the console branch 3 times, most recently from 120a1b5 to cdc0a65 Compare October 2, 2020 23:37
@erights erights marked this pull request as ready for review October 5, 2020 18:13
@erights erights requested a review from kriskowal October 5, 2020 18:14
@erights
Copy link
Contributor Author

erights commented Oct 5, 2020

Ready for review again! Includes new design doc at https://github.com/Agoric/SES-shim/tree/console/packages/ses/src/error

Copy link
Member

@kriskowal kriskowal left a comment

Choose a reason for hiding this comment

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

Approved with nits. Thanks!

packages/ses/src/commons.js Outdated Show resolved Hide resolved
packages/ses/src/commons.js Outdated Show resolved Hide resolved
packages/ses/src/error/README.md Outdated Show resolved Hide resolved
packages/ses/src/error/README.md Outdated Show resolved Hide resolved
packages/ses/src/error/README.md Outdated Show resolved Hide resolved
packages/ses/src/error/README.md Outdated Show resolved Hide resolved
packages/ses/src/evaluate.js Show resolved Hide resolved
packages/ses/src/module-load.js Outdated Show resolved Hide resolved
@@ -0,0 +1,337 @@
// TODO The following two lines came from agoric-sdk with already supports ava.
Copy link
Member

Choose a reason for hiding this comment

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

TODO

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure what you want me to do here. In moving this package from the agoric-sdk monorepo to the SES-shim monorepo, I had to regress the testing to use tap or tape rather than AVA. I put this comment there to help when we reverse this regression, once SES-shim switches to use AVA.

I'll leave this unresolved, but I am not inclined to postpone merging till we resolve this.

// This is just a token standalone test of the `assert` module. The real test
// is in assert-log.test.js which also uses the logging console.

// TODO The following line came from agoric-sdk which already supports ava.
Copy link
Member

Choose a reason for hiding this comment

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

TODO

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Likewise

@erights erights merged commit 1d03d3f into master Oct 12, 2020
@erights erights deleted the console branch October 12, 2020 06:15
@erights erights mentioned this pull request Nov 27, 2020
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

Successfully merging this pull request may close these issues.

Features needed from Error + console + assert
3 participants