[sdk/nodejs] Use log.error to log uncaught errors (#5910)

`log.error` will call the engine's `log` gRPC endpoint (if the engine is available; otherwise it will write to `console.error`) with `LogSeverity.ERROR`, which tell the engine to stop processing further resource operations.

Without this, any uncaught errors (such as input validation errors done inside `apply`) would be written to stderr, but wouldn't actually result in an update error.
This commit is contained in:
Justin Van Patten 2020-12-10 08:53:25 -08:00 committed by GitHub
parent 3994fa8c22
commit 4747be7b9f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -19,6 +19,7 @@ import * as grpc from "@grpc/grpc-js";
import { Provider } from "./provider";
import * as log from "../log";
import { Inputs, Output, output } from "../output";
import * as resource from "../resource";
import * as runtime from "../runtime";
@ -414,7 +415,9 @@ export async function main(provider: Provider, args: string[]) {
const uncaughtHandler = (err: Error) => {
if (!uncaughtErrors.has(err)) {
uncaughtErrors.add(err);
console.error(err.stack || err.message || ("" + err));
// Use `pulumi.log.error` here to tell the engine there was a fatal error, which should
// stop processing subsequent resource operations.
log.error(err.stack || err.message || ("" + err));
}
};