Skip to content

Commit

Permalink
fix: Handle empty policy directory (#699)
Browse files Browse the repository at this point in the history
  • Loading branch information
erezrokah committed May 11, 2022
1 parent 413a2cf commit 6acd308
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/policy/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ package policy

import (
"context"
"errors"
"fmt"
"net/url"
"os"
"path/filepath"
"strings"

"github.com/cloudquery/cloudquery/internal/getter"
"github.com/cloudquery/cq-provider-sdk/provider/diag"
"github.com/spf13/afero"
)

Expand Down Expand Up @@ -59,6 +62,9 @@ func LoadSource(ctx context.Context, installDir, source string) ([]byte, *Meta,

data, err := afero.ReadFile(afero.NewOsFs(), filepath.Join(policyDir, defaultPolicyFileName))
if err != nil {
if errors.Is(err, os.ErrNotExist) {
return nil, nil, diag.FromError(fmt.Errorf("could not find %q in %q. Please verify it exists", defaultPolicyFileName, source), diag.USER)
}
// TODO: make more descriptive error
return nil, nil, fmt.Errorf("failed to open source: %w", err)
}
Expand Down

0 comments on commit 6acd308

Please sign in to comment.