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

Improve nodejs automation api inline error handling #6237

Merged
merged 3 commits into from Feb 2, 2021

Conversation

EvanBoyle
Copy link
Contributor

This changeset adds several improvements to our error handling for nodejs inline programs run via Automation API. Along the way, I also cleaned up a bunch of unused functionality from server.ts (exposing a result promise, providing an unused CLI exit code, etc). Summary of fixes:

  1. Run user code in a try/finally to ensure the gRPC LanguageServer is always torn down cleanly (otherwise causes failed programs to hang)
  2. Run the leaked promise detector after the CLI has exited, this is more consistent with the behavior of CLI programs (detector normally runs as late as possible when the process exits). This fixes the erroneous messages observed in Secret handing with the Automation API weirdness #6153 Non deterministic Promise leak #5853
  3. Ensure that all kinds of Error are handled properly, even if user code throws an error without any details, exception message, etc.
  4. LanguageServer.Run should respond with errors via calling the callback function https://avi.im/grpc-errors/#node

Fixes #6153
Fixes #5853
Fixes #6057

@EvanBoyle EvanBoyle added the impact/no-changelog-required This issue doesn't require a CHANGELOG update label Feb 2, 2021
Copy link
Member

@komalali komalali left a comment

Choose a reason for hiding this comment

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

Couple of questions but otherwise LGTM!

const defaultMessage = err.stack || err.message || ("" + err);
let defaultMessage = ""
if (!!err) {
defaultMessage = err.stack || err.message || ("" + err);
Copy link
Member

Choose a reason for hiding this comment

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

What's the relevance of the "" + err? Is that a string conversion?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yup

let upResult;
try {
upResult = await this.runPulumiCmd(args, opts?.onOutput);
onExit();
Copy link
Member

Choose a reason for hiding this comment

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

Is this onExit() necessary? Doesn't the finally block run regardless of error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right. Updated.

@EvanBoyle EvanBoyle merged commit decfed0 into master Feb 2, 2021
@pulumi-bot pulumi-bot deleted the evan/autoNodeRuntimeErrors branch February 2, 2021 22:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
impact/no-changelog-required This issue doesn't require a CHANGELOG update
Projects
None yet
3 participants