Fix panic when using commands w/o Pulumi.yaml (#492)
Calls to `NewProjectWorkspace` will panic if there is no Pulumi.yaml found in the folder hierarchy. Simple repo: ``` git init pulumi init pulumi stack init x ``` `DetectPackage` will search until it gets to the `.pulumi` directory or finds a `Pulumi.yaml` file. In the case of the former, we pass "" to `LoadPackage` which then asserts because the file doesn't exist. We now detect this condition and surface an error to the user. The error text is patterned after running a git command when there is no .git folder found: fatal: Not a git repository (or any of the parent directories): .git
This commit is contained in:
parent
cdb2c79e8e
commit
bd5e54d63e
|
@ -9,6 +9,7 @@ import (
|
|||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/pulumi/pulumi/pkg/pack"
|
||||
"github.com/pulumi/pulumi/pkg/tokens"
|
||||
)
|
||||
|
@ -28,6 +29,8 @@ type projectWorkspace struct {
|
|||
repo *Repository // the repo this workspace is associated with.
|
||||
}
|
||||
|
||||
// NewProjectWorkspace creates a new Pulumi workspace in the given directory. Requires a
|
||||
// Pulumi.yaml file be present in the folder hierarchy between dir and the .pulumi folder.
|
||||
func NewProjectWorkspace(dir string) (W, error) {
|
||||
repo, err := GetRepository(dir)
|
||||
if err != nil {
|
||||
|
@ -38,6 +41,9 @@ func NewProjectWorkspace(dir string) (W, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if project == "" {
|
||||
return nil, errors.New("no Pulumi project file found, are you missing a Pulumi.yaml file?")
|
||||
}
|
||||
|
||||
pkg, err := pack.Load(project)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in a new issue