Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Commit

Permalink
bubble up errors
Browse files Browse the repository at this point in the history
  • Loading branch information
CecileRobertMichon committed May 7, 2018
1 parent a10d08c commit 3753591
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (dc *deployCmd) validate(cmd *cobra.Command, args []string) error {

dc.client, err = dc.authArgs.getClient()
if err != nil {
return fmt.Errorf(fmt.Sprintf("failed to get client")) // TODO: cleanup
return fmt.Errorf("failed to get client: %s", err.Error()) // TODO: cleanup
}

// autofillApimodel calls log.Fatal() directly and does not return errors
Expand Down
13 changes: 7 additions & 6 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package cmd

import (
"fmt"

"github.com/Azure/acs-engine/pkg/armhelpers"
"github.com/Azure/go-autorest/autorest/azure"
uuid "github.com/satori/go.uuid"
Expand Down Expand Up @@ -76,22 +78,22 @@ func (authArgs *authArgs) getClient() (*armhelpers.AzureClient, error) {

if authArgs.AuthMethod == "client_secret" {
if authArgs.ClientID.String() == "00000000-0000-0000-0000-000000000000" || authArgs.ClientSecret == "" {
log.Fatal(`--client-id and --client-secret must be specified when --auth-method="client_secret"`)
return nil, fmt.Errorf(`--client-id and --client-secret must be specified when --auth-method="client_secret"`)
}
// try parse the UUID
} else if authArgs.AuthMethod == "client_certificate" {
if authArgs.ClientID.String() == "00000000-0000-0000-0000-000000000000" || authArgs.CertificatePath == "" || authArgs.PrivateKeyPath == "" {
log.Fatal(`--client-id and --certificate-path, and --private-key-path must be specified when --auth-method="client_certificate"`)
return nil, fmt.Errorf(`--client-id and --certificate-path, and --private-key-path must be specified when --auth-method="client_certificate"`)
}
}

if authArgs.SubscriptionID.String() == "00000000-0000-0000-0000-000000000000" {
log.Fatal("--subscription-id is required (and must be a valid UUID)")
return nil, fmt.Errorf("--subscription-id is required (and must be a valid UUID)")
}

env, err := azure.EnvironmentFromName(authArgs.RawAzureEnvironment)
if err != nil {
log.Fatal("failed to parse --azure-env as a valid target Azure cloud environment")
return nil, fmt.Errorf("failed to parse --azure-env as a valid target Azure cloud environment")
}

var client *armhelpers.AzureClient
Expand All @@ -103,8 +105,7 @@ func (authArgs *authArgs) getClient() (*armhelpers.AzureClient, error) {
case "client_certificate":
client, err = armhelpers.NewAzureClientWithClientCertificateFile(env, authArgs.SubscriptionID.String(), authArgs.ClientID.String(), authArgs.CertificatePath, authArgs.PrivateKeyPath)
default:
log.Fatalf("--auth-method: ERROR: method unsupported. method=%q.", authArgs.AuthMethod)
return nil, nil // unreachable
return nil, fmt.Errorf("--auth-method: ERROR: method unsupported. method=%q.", authArgs.AuthMethod)
}
if err != nil {
return nil, err
Expand Down

0 comments on commit 3753591

Please sign in to comment.