Skip to content

Commit

Permalink
Updates following code review (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
bendbennett committed Jul 1, 2022
1 parent a53a450 commit dd331c5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
13 changes: 13 additions & 0 deletions internal/diagnostics/diagnostics.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,16 @@ func HashGenerationError(errMsg string) diag.Diagnostics {

return diags
}

func RandomnessGenerationError(errMsg string) diag.Diagnostics {
var diags diag.Diagnostics

diags.AddError(
"Randomness Generation Error",
"While attempting to generate a random value for this resource, an insufficient number of random bytes were generated.\n\n"+
RetryMsg+
fmt.Sprintf("Original Error: %s", errMsg),
)

return diags
}
4 changes: 1 addition & 3 deletions internal/provider/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import (
//nolint:unparam
func protoV6ProviderFactories() map[string]func() (tfprotov6.ProviderServer, error) {
return map[string]func() (tfprotov6.ProviderServer, error){
"random": func() (tfprotov6.ProviderServer, error) {
return providerserver.NewProtocol6WithError(New())()
},
"random": providerserver.NewProtocol6WithError(New()),
}
}

Expand Down
7 changes: 1 addition & 6 deletions internal/provider/resource_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,7 @@ func (r *idResource) Create(ctx context.Context, req tfsdk.CreateResourceRequest

n, err := rand.Reader.Read(bytes)
if int64(n) != byteLength {
resp.Diagnostics.AddError(
"Randomness Generation Error",
"While attempting to generate a random value for this resource, an insufficient number of random bytes were generated. Most commonly, this is a hardware or operating system issue where their random number generator does not provide a sufficient randomness source. Otherwise, it may represent an issue in the randomness handling of the provider.\n\n"+
"Retry the Terraform operation. If the error still occurs or happens regularly, please contact the provider developer with hardware and operating system information.\n\n"+
fmt.Sprintf("Original Error: %s", err),
)
resp.Diagnostics.Append(diagnostics.RandomnessGenerationError(err.Error())...)
return
}
if err != nil {
Expand Down

0 comments on commit dd331c5

Please sign in to comment.