Skip to content

Commit

Permalink
Handle permission (and other) errors during os.Stat(imposters_path)
Browse files Browse the repository at this point in the history
  • Loading branch information
joanlopez committed Jun 13, 2024
1 parent a066757 commit 5c3d7ca
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions internal/server/http/imposter.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,16 @@ type ImposterFs struct {
}

func NewImposterFS(path string) (ImposterFs, error) {
// TODO: What if user lacks permissions?
if _, err := os.Stat(path); os.IsNotExist(err) {
return ImposterFs{}, fmt.Errorf("%w: the directory %s doesn't exists", err, path)
_, err := os.Stat(path)
if err != nil {
switch {
case os.IsNotExist(err):
return ImposterFs{}, fmt.Errorf("the directory '%s' does not exist", path)
case os.IsPermission(err):
return ImposterFs{}, fmt.Errorf("could not read the directory '%s': permission denied", path)
default:
return ImposterFs{}, fmt.Errorf("could not read the directory '%s': %w", path, err)
}
}

return ImposterFs{
Expand Down

0 comments on commit 5c3d7ca

Please sign in to comment.