Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,14 @@ For more options, run 'func deploy --help'`, err)
return f.Stamp()
}

type ErrEnvNotExist struct {
Name string
}

func (e ErrEnvNotExist) Error() string {
return fmt.Sprintf("environment variable %q does not exist", e.Name)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

can we put this into pkg/functions/errors.go please to keep consistent with the place for error definitions.
Otherwise looks good to me

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey @gauron99 , Thanks for this suggestion ! Now Is it good to go ?


// build when flag == 'auto' and the function is out-of-date, or when the
// flag value is explicitly truthy such as 'true' or '1'. Error if flag
// is neither 'auto' nor parseable as a boolean. Return CLI-specific error
Expand Down
14 changes: 14 additions & 0 deletions cmd/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,20 @@ func TestDeploy_Envs(t *testing.T) {
}

// TODO: create and test typed errors for ErrEnvNotExist etc.

cmd = NewDeployCmd(NewTestClient())
cmd.SetArgs([]string{"--env=DOES_NOT_EXIST-"})
err = cmd.Execute()

var e *ErrEnvNotExist
if !errors.As(err, &e) {
t.Fatalf("expected ErrEnvNotExist, got '%v'", err)
}

if e.Name != "DOES_NOT_EXIST" {
t.Fatalf("expected env name 'DOES_NOT_EXIST', got '%v'", e.Name)
}

}

// TestDeploy_FunctionContext ensures that the function contextually relevant
Expand Down
5 changes: 5 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,13 +298,18 @@ func mergeEnvs(envs []fn.Env, envToUpdate *util.OrderedMap, envToRemove []string
}

for _, name := range envToRemove {
found := false
for i, envVar := range envs {
if *envVar.Name == name {
envs = append(envs[:i], envs[i+1:]...)
counter++
found = true
break
}
}
if !found {
return nil, 0, &ErrEnvNotExist{Name: name}
}
}

errMsg := fn.ValidateEnvs(envs)
Expand Down
Loading