Skip to content

Commit 45a57e6

Browse files
committed
Improve device create error
1 parent c42f685 commit 45a57e6

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

command/device/create.go

+9-5
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,15 @@ func Create(params *CreateParams) (*DeviceInfo, error) {
8484
id: dev.Id,
8585
}
8686
if err = prov.run(); err != nil {
87-
// TODO: retry to delete the device if it returns an error.
88-
// In alternative: encapsulate also this error.
89-
iotClient.DeviceDelete(dev.Id)
90-
err = fmt.Errorf("%s: %w", "cannot provision device", err)
91-
return nil, err
87+
if errDel := iotClient.DeviceDelete(dev.Id); errDel != nil {
88+
return nil, fmt.Errorf(
89+
"device was NOT successfully provisioned but " +
90+
"now we can't delete it from the cloud - please check " +
91+
"it on the web application.\n\nProvision error: " + err.Error() +
92+
"\nDeletion error: " + errDel.Error(),
93+
)
94+
}
95+
return nil, fmt.Errorf("cannot provision device: %w", err)
9296
}
9397

9498
devInfo := &DeviceInfo{

0 commit comments

Comments
 (0)