Skip to content

Commit

Permalink
Ensuring the error message is properly formatted when it contains new…
Browse files Browse the repository at this point in the history
…lines. (Issue 346) (#347)

Co-authored-by: Fernando Villalba <fernando@civo.com>
  • Loading branch information
fernando-villalba and Fernando Villalba authored Sep 25, 2024
1 parent 2adc815 commit 551accf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 4 additions & 2 deletions civo/instances/resource_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import (
"encoding/base64"
"errors"
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
"log"
"strings"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"

"github.com/civo/civogo"
"github.com/civo/terraform-provider-civo/internal/utils"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
Expand Down Expand Up @@ -285,7 +286,8 @@ func resourceInstanceCreate(ctx context.Context, d *schema.ResourceData, m inter
if parseErr == nil {
err = customErr
}
return diag.Errorf("[ERR] failed to create instance: %s", err)
// quota errors introduce new line after each missing quota, causing formatting issues:
return diag.Errorf("[ERR] failed to create instance: %s", strings.ReplaceAll(err.Error(), "\n", " "))
}

d.SetId(instance.ID)
Expand Down
3 changes: 2 additions & 1 deletion civo/kubernetes/resource_kubernetes_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,8 @@ func resourceKubernetesClusterCreate(ctx context.Context, d *schema.ResourceData
log.Printf("[INFO] kubernertes config %+v", config)
resp, err := apiClient.NewKubernetesClusters(config)
if err != nil {
return diag.Errorf("[ERR] failed to create the kubernetes cluster: %s", err)
// quota errors introduce new line after each missing quota, causing formatting issues:
return diag.Errorf("[ERR] failed to create the kubernetes cluster: %s", strings.ReplaceAll(err.Error(), "\n", " "))
}

d.SetId(resp.ID)
Expand Down

0 comments on commit 551accf

Please sign in to comment.