Skip to content

fix(config): create new scw configuration if not found #4864

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
7 changes: 6 additions & 1 deletion internal/namespaces/config/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,12 @@ The only allowed attributes are access_key, secret_key, default_organization_id,
configPath := core.ExtractConfigPath(ctx)
config, err := scw.LoadConfigFromPath(configPath)
if err != nil {
return nil, err
if strings.Contains(err.Error(), "no such file or directory") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could an explicit error be defined and used with error.As here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the error returned is

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

error.As cannot be used unfortunately because the path field is private if errors.As(err, &scw.ConfigFileNotFoundError{path: configPath}) {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the path be exported instead?

fmt.Fprintln(os.Stdout, "config file not found, will attempt to create it")
config = &scw.Config{}
} else {
return nil, err
}
}

// send_telemetry is the only key that is not in a profile but in the config object directly
Expand Down
Loading