Improve failure messages (#932)

This improves the failure messages in two circumstances:

1) If the resource monitor RPC connection is missing.  This can happen
   two ways: either you run a Pulumi program using vanilla Node.js, instead
   of the CLI, or you've accidentally loaded the Pulumi SDK more than once.

2) Failure to load the custom Pulumi SDK Node.js extension.  This is a new
   addition and would happen if you tried running a Pulumi program using a
   vanilla Node.js, rather than using the Pulumi CLI.
This commit is contained in:
Joe Duffy 2018-02-14 09:55:02 -08:00 committed by GitHub
parent 5d2f21d527
commit 444ebdd1b5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 11 deletions

View file

@ -169,4 +169,3 @@ class ConfigMissingError extends RunError {
);
}
}

View file

@ -3,6 +3,7 @@
import * as crypto from "crypto";
import { relative as pathRelative } from "path";
import * as ts from "typescript";
import { RunError } from "../errors";
import * as log from "../log";
import * as resource from "../resource";
import { debuggablePromise } from "./debuggable";
@ -15,7 +16,14 @@ import { debuggablePromise } from "./debuggable";
//
// `process.binding` invokes the Node bootstrap module loader in order to
// get to our builtin module.
const nativeruntime = (<any>process).binding("pulumi_closure");
let nativeruntime: any;
try {
nativeruntime = (<any>process).binding("pulumi_closure");
}
catch (err) {
throw new RunError(
`Failed to load custom Pulumi SDK Node.js extension; are you running using the Pulumi CLI? (${err.message})`);
}
/**
* Closure represents the serialized form of a JavaScript serverless function.

View file

@ -69,4 +69,3 @@ export function getConfigEnv(): {[key: string]: string} {
}
return {};
}

View file

@ -1,5 +1,6 @@
// Copyright 2016-2017, Pulumi Corporation. All rights reserved.
import { RunError } from "../errors";
import { Resource } from "../resource";
import { debuggablePromise } from "./debuggable";
@ -29,11 +30,6 @@ export let options: Options = <any>{
includeStackTraces: true,
};
/**
* configured is set to true once configuration has been set.
*/
let configured: boolean;
/**
* hasMonitor returns true if we are currently connected to a resource monitoring service.
*/
@ -45,9 +41,10 @@ export function hasMonitor(): boolean {
* getMonitor returns the current resource monitoring service client for RPC communications.
*/
export function getMonitor(): Object {
if (!configured) {
configured = true;
console.warn("warning: Pulumi Fabric monitor is missing; no resources will be created");
if (!options.monitor) {
throw new RunError(
"Pulumi program not connected to the engine -- are you running with the `pulumi` CLI?\n" +
"This can also happen if you've loaded the Pulumi SDK module multiple times into the same proces");
}
return options.monitor;
}
@ -66,6 +63,11 @@ export function serialize(): boolean {
return !options.parallel || options.parallel <= 1;
}
/**
* configured is set to true once configuration has been set.
*/
let configured: boolean;
/**
* configure initializes the current resource monitor and engine RPC connections, and whether we are performing a "dry
* run" (preview), versus a real deployment, and so on. It may only be called once.