Skip to content

Commit

Permalink
avoid error catching in Exists to aid readability
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko committed Jul 1, 2022
1 parent 5d6103c commit 11c70d8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
4 changes: 4 additions & 0 deletions internal/state/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,10 @@ func (s *ModuleStore) Exists(path string) (bool, error) {

_, err := moduleByPath(txn, path)
if err != nil {
if IsModuleNotFound(err) {
return false, nil
}

return false, err
}

Expand Down
14 changes: 6 additions & 8 deletions internal/walker/walker.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

"github.com/hashicorp/terraform-ls/internal/document"
"github.com/hashicorp/terraform-ls/internal/job"
"github.com/hashicorp/terraform-ls/internal/state"
"github.com/hashicorp/terraform-ls/internal/terraform/datadir"
)

Expand Down Expand Up @@ -191,14 +190,13 @@ func (w *Walker) walk(ctx context.Context, dir document.DirHandle) error {
if info.Name() == datadir.DataDirName {
w.logger.Printf("found module %s", dir)

_, err := w.modStore.Exists(dir)
exists, err := w.modStore.Exists(dir)
if err != nil {
if state.IsModuleNotFound(err) {
err := w.modStore.Add(dir)
if err != nil {
return err
}
} else {
return err
}
if !exists {
err := w.modStore.Add(dir)
if err != nil {
return err
}
}
Expand Down

0 comments on commit 11c70d8

Please sign in to comment.