-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better error messages / error codes (#5)
* Better error messages / error codes * Fixed review issues
- Loading branch information
Janos Pasztor
authored
Jul 18, 2021
1 parent
577d015
commit 627e5a4
Showing
31 changed files
with
935 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
linters: | ||
enable: | ||
- asciicheck | ||
- bodyclose | ||
- dupl | ||
- errorlint | ||
- exportloopref | ||
- funlen |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,26 @@ | ||
package ovirtclient | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
func (o *oVirtClient) GetCluster(id string) (cluster Cluster, err error) { | ||
response, err := o.conn.SystemService().ClustersService().ClusterService(id).Get().Send() | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to fetch cluster ID %s (%w)", id, err) | ||
return nil, wrap(err, "failed to fetch cluster ID %s", id) | ||
} | ||
sdkCluster, ok := response.Cluster() | ||
if !ok { | ||
return nil, fmt.Errorf("no cluster returned when getting cluster ID %s", id) | ||
return nil, newError( | ||
ENotFound, | ||
"no cluster returned when getting cluster ID %s", | ||
id, | ||
) | ||
} | ||
cluster, err = convertSDKCluster(sdkCluster) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to convert cluster %s (%w)", id, err) | ||
return nil, wrap( | ||
err, | ||
EBug, | ||
"failed to convert cluster %s", | ||
id, | ||
) | ||
} | ||
return cluster, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,32 @@ | ||
package ovirtclient | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
func (o *oVirtClient) GetDisk(diskID string) (Disk, error) { | ||
response, err := o.conn.SystemService().DisksService().DiskService(diskID).Get().Send() | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to fetch disk %s (%w)", diskID, err) | ||
return nil, wrap( | ||
err, | ||
EUnidentified, | ||
"failed to fetch disk %s", | ||
diskID, | ||
) | ||
} | ||
sdkDisk, ok := response.Disk() | ||
if !ok { | ||
return nil, fmt.Errorf("disk %s response did not contain a disk (%w)", diskID, err) | ||
return nil, wrap( | ||
err, | ||
ENotFound, | ||
"disk %s response did not contain a disk", | ||
diskID, | ||
) | ||
} | ||
disk, err := convertSDKDisk(sdkDisk) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to convert disk %s (%w)", diskID, err) | ||
return nil, wrap( | ||
err, | ||
EBug, | ||
"failed to convert disk %s", | ||
diskID, | ||
) | ||
} | ||
return disk, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,34 @@ | ||
package ovirtclient | ||
|
||
import ( | ||
"fmt" | ||
"context" | ||
"time" | ||
) | ||
|
||
func (o *oVirtClient) RemoveDisk(diskID string) error { | ||
if _, err := o.conn.SystemService().DisksService().DiskService(diskID).Remove().Send(); err != nil { | ||
return fmt.Errorf("failed to remove disk %s (%w)", diskID, err) | ||
func (o *oVirtClient) RemoveDisk(ctx context.Context, diskID string) error { | ||
var lastError EngineError | ||
for { | ||
_, err := o.conn.SystemService().DisksService().DiskService(diskID).Remove().Send() | ||
if err == nil { | ||
return err | ||
} | ||
lastError = wrap( | ||
err, | ||
EUnidentified, | ||
"failed to remove disk %s", | ||
diskID, | ||
) | ||
if !lastError.CanAutoRetry() { | ||
return lastError | ||
} | ||
select { | ||
case <-ctx.Done(): | ||
return wrap( | ||
lastError, | ||
ETimeout, | ||
"timeout while removing disk", | ||
) | ||
case <-time.After(10 * time.Second): | ||
} | ||
} | ||
return nil | ||
} |
Oops, something went wrong.