Skip to content

Fix type safety and formatting issues in provider code #844

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 13, 2025
Merged
Changes from all 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
kind: fixed
body: Fixed type safety and formatting issues including missing string validation, interface assertions, and escaped newline formatting
custom:
Issue: 825
4 changes: 2 additions & 2 deletions internal/api/client_test.go
Original file line number Diff line number Diff line change
@@ -39,10 +39,10 @@ func TestUnitApiClient_GetConfig(t *testing.T) {
}

switch err.(type) {
case customerrors.UrlFormatError:
case *customerrors.UrlFormatError:
return
default:
t.Errorf("Expected error type %s but got %s", reflect.TypeOf(customerrors.UrlFormatError{}), reflect.TypeOf(err))
t.Errorf("Expected error type %s but got %s", reflect.TypeOf(&customerrors.UrlFormatError{}), reflect.TypeOf(err))
}
}

8 changes: 4 additions & 4 deletions internal/customerrors/url_format_error.go
Original file line number Diff line number Diff line change
@@ -7,21 +7,21 @@ import (
"fmt"
)

var _ error = UrlFormatError{}
var _ error = (*UrlFormatError)(nil)

type UrlFormatError struct {
Url string
Err error
}

func NewUrlFormatError(url string, err error) error {
return UrlFormatError{
return &UrlFormatError{
Err: err,
Url: url,
}
}

func (e UrlFormatError) Error() string {
func (e *UrlFormatError) Error() string {
errorMsg := ""
if e.Err != nil {
errorMsg = e.Err.Error()
@@ -30,6 +30,6 @@ func (e UrlFormatError) Error() string {
return fmt.Sprintf("Request url must be an absolute url: '%s' : '%s'", e.Url, errorMsg)
}

func (e UrlFormatError) Unwrap() error {
func (e *UrlFormatError) Unwrap() error {
return e.Err
}
2 changes: 1 addition & 1 deletion internal/customtypes/uuid_value.go
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ import (

const (
UUIDTypeErrorInvalidStringHeader = "Invalid UUID String Value"
UUIDTypeErrorInvalidStringDetails = `A string value was provided that is not valid UUID string format.\n\nGiven Value: %s\n`
UUIDTypeErrorInvalidStringDetails = "A string value was provided that is not valid UUID string format.\n\nGiven Value: %s\n"
)

var (
12 changes: 12 additions & 0 deletions internal/services/licensing/resource_billing_policy.go
Original file line number Diff line number Diff line change
@@ -68,10 +68,16 @@ func (r *BillingPolicyResource) Schema(ctx context.Context, req resource.SchemaR
"name": schema.StringAttribute{
MarkdownDescription: "The name of the billing policy",
Required: true,
Validators: []validator.String{
stringvalidator.LengthAtLeast(1),
},
},
"location": schema.StringAttribute{
MarkdownDescription: "The location of the billing policy",
Required: true,
Validators: []validator.String{
stringvalidator.LengthAtLeast(1),
},
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
},
@@ -98,13 +104,19 @@ func (r *BillingPolicyResource) Schema(ctx context.Context, req resource.SchemaR
"resource_group": schema.StringAttribute{
MarkdownDescription: "The resource group of the billing instrument",
Required: true,
Validators: []validator.String{
stringvalidator.LengthAtLeast(1),
},
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
},
},
"subscription_id": schema.StringAttribute{
MarkdownDescription: "The subscription id of the billing instrument",
Required: true,
Validators: []validator.String{
stringvalidator.LengthAtLeast(1),
},
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
},