Skip to content

Commit

Permalink
refactor: inline errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Tinyblargon committed Feb 29, 2024
1 parent 62814ec commit bb6e576
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions proxmox/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@ func (config ConfigSnapshot) mapToApiValues() map[string]interface{} {

// Creates a snapshot and validates the input
func (config ConfigSnapshot) Create(c *Client, vmr *VmRef) (err error) {
err = c.CheckVmRef(vmr)
if err != nil {
if err = c.CheckVmRef(vmr); err != nil {
return
}
err = config.Validate()
if err != nil {
if err = config.Validate(); err != nil {
return
}
return config.Create_Unsafe(c, vmr)
Expand Down Expand Up @@ -59,8 +57,7 @@ func (config ConfigSnapshot) Validate() error {
type rawSnapshots []interface{}

func ListSnapshots(c *Client, vmr *VmRef) (rawSnapshots, error) {
err := c.CheckVmRef(vmr)
if err != nil {
if err := c.CheckVmRef(vmr); err != nil {
return nil, err
}
return c.GetItemConfigInterfaceArray("/nodes/"+vmr.node+"/"+vmr.vmType+"/"+strconv.Itoa(vmr.vmId)+"/snapshot/", "Guest", "SNAPSHOTS")
Expand Down Expand Up @@ -150,12 +147,10 @@ const (

// Deletes the specified snapshot, validates the input
func (snap SnapshotName) Delete(c *Client, vmr *VmRef) (exitStatus string, err error) {
err = c.CheckVmRef(vmr)
if err != nil {
if err = c.CheckVmRef(vmr); err != nil {
return
}
err = snap.Validate()
if err != nil {
if err = snap.Validate(); err != nil {
return
}
// TODO check if snapshot exists
Expand All @@ -169,8 +164,7 @@ func (snap SnapshotName) Delete_Unsafe(c *Client, vmr *VmRef) (exitStatus string

// Rollback to the specified snapshot, validates the input
func (snap SnapshotName) Rollback(c *Client, vmr *VmRef) (exitStatus string, err error) {
err = c.CheckVmRef(vmr)
if err != nil {
if err = c.CheckVmRef(vmr); err != nil {
return
}
if err = snap.Validate(); err != nil {
Expand All @@ -187,12 +181,10 @@ func (snap SnapshotName) Rollback_Unsafe(c *Client, vmr *VmRef) (exitStatus stri

// Updates the description of the specified snapshot, validates the input
func (snap SnapshotName) UpdateDescription(c *Client, vmr *VmRef, description string) (err error) {
err = c.CheckVmRef(vmr)
if err != nil {
if err = c.CheckVmRef(vmr); err != nil {
return
}
err = snap.Validate()
if err != nil {
if err = snap.Validate(); err != nil {
return
}
// TODO check if snapshot exists
Expand Down

0 comments on commit bb6e576

Please sign in to comment.