Skip to content

Commit

Permalink
Better error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
karelorigin committed Apr 25, 2022
1 parent 07e00d7 commit 6c51f2d
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions local/resource_local_sticky_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package local

import (
"context"
"errors"
"fmt"
"io/fs"
"io/ioutil"
Expand Down Expand Up @@ -92,12 +91,12 @@ func (r resourceLocalStickyFile) Read(ctx context.Context, req tfsdk.ReadResourc
}

_, err := os.Stat(file.Path.Value)
if !(err == nil || errors.Is(err, os.ErrNotExist)) {
if !(err == nil || os.IsNotExist(err)) {
return diag.NewErrorDiagnostic("could not verify whether path exists or not", err.Error())
}

// File already exists, skip
if !errors.Is(err, os.ErrNotExist) {
if os.IsExist(err) {
return nil
}

Expand Down Expand Up @@ -145,12 +144,12 @@ func (r resourceLocalStickyFile) Delete(ctx context.Context, req tfsdk.DeleteRes
}

_, err := os.Stat(file.Path.Value)
if err != nil {
if err != nil && !os.IsNotExist(err) {
return diag.NewErrorDiagnostic("could not verify whether path exists or not", err.Error())
}

// Delete file if it exists
if !errors.Is(err, os.ErrNotExist) {
if !os.IsNotExist(err) {
if err := os.Remove(file.Path.Value); err != nil {
return diag.NewErrorDiagnostic("unable to remove file from disk", err.Error())
}
Expand Down

0 comments on commit 6c51f2d

Please sign in to comment.