Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions scw/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"syscall"
"text/template"

"github.com/scaleway/scaleway-sdk-go/internal/auth"
Expand Down Expand Up @@ -170,6 +171,9 @@ func LoadConfigFromPath(path string) (*Config, error) {

file, err := ioutil.ReadFile(path)
if err != nil {
if pathError, isPathError := err.(*os.PathError); isPathError && pathError.Err == syscall.ENOENT {
return nil, configFileNotFound(pathError.Path)
}
return nil, errors.Wrap(err, "cannot read config file")
}

Expand Down
2 changes: 1 addition & 1 deletion scw/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func TestLoadProfileAndActiveProfile(t *testing.T) {
},
{
name: "No config",
expectedError: "scaleway-sdk-go: cannot read config file: open {HOME}/.config/scw/config.yaml: no such file or directory",
expectedError: "scaleway-sdk-go: cannot read config file {HOME}/.config/scw/config.yaml: no such file or directory",
env: map[string]string{
"HOME": "{HOME}",
},
Expand Down
15 changes: 15 additions & 0 deletions scw/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,18 @@ func (e InvalidClientOptionError) IsScwSdkError() {}
func (e InvalidClientOptionError) Error() string {
return fmt.Sprintf("scaleway-sdk-go: %s", e.errorType)
}

// ConfigFileNotFound indicates that the config file could not be found
type ConfigFileNotFoundError struct {
path string
}

func configFileNotFound(path string) *ConfigFileNotFoundError {
return &ConfigFileNotFoundError{path: path}
}

// ConfigFileNotFoundError implements the SdkError interface
func (e ConfigFileNotFoundError) IsScwSdkError() {}
func (e ConfigFileNotFoundError) Error() string {
return fmt.Sprintf("scaleway-sdk-go: cannot read config file %s: no such file or directory", e.path)
}
2 changes: 1 addition & 1 deletion scw/load_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func TestLoad(t *testing.T) {
env: map[string]string{
scwConfigPathEnv: "{HOME}/fake/test.conf",
},
expectedError: "scaleway-sdk-go: cannot read config file: open {HOME}/fake/test.conf: no such file or directory",
expectedError: "scaleway-sdk-go: cannot read config file {HOME}/fake/test.conf: no such file or directory",
},
{
name: "Err: custom-path config with invalid V2",
Expand Down