Skip to content
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

fix: change config upgrade to avoid an empty config file on error #3149

Merged
merged 2 commits into from
Nov 22, 2022
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: 2 additions & 2 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@

- [#3114](https://github.com/ignite/cli/pull/3114) Fix out of gas issue when approving many requests
- [#3068](https://github.com/ignite/cli/pull/3068) Fix REST codegen method casing bug
- [#3031](https://github.com/ignite/cli/pull/3031) Move keeper hooks to after all keepers initialized in `app.go`
template.
- [#3031](https://github.com/ignite/cli/pull/3031) Move keeper hooks to after all keepers initialized in `app.go` template.
- [#3098](https://github.com/ignite/cli/issues/3098) Fix config upgrade issue that left config empty on error.

## [`v0.25.2`](https://github.com/ignite/cli/releases/tag/v0.25.1)

Expand Down
2 changes: 1 addition & 1 deletion ignite/chainconfig/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
func Parse(configFile io.Reader) (*Config, error) {
cfg, err := parse(configFile)
if err != nil {
return cfg, err
return cfg, fmt.Errorf("error parsing config file: %w", err)
}

return cfg, validateConfig(cfg)
Expand Down
12 changes: 6 additions & 6 deletions ignite/cmd/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,15 @@ func configMigrationPreRunHandler(cmd *cobra.Command, args []string) (err error)
session.Printf("%s %s\n", icons.Info, colors.Infof(msgMigration, version, chainconfig.LatestVersion))
}

file, err := os.OpenFile(configPath, os.O_WRONLY|os.O_TRUNC, 0o755)
if err != nil {
// Convert the current config to the latest version and update the YAML file
var buf bytes.Buffer
if err := chainconfig.MigrateLatest(bytes.NewReader(rawCfg), &buf); err != nil {
return err
}

defer file.Close()

// Convert the current config to the latest version and update the YAML file
return chainconfig.MigrateLatest(bytes.NewReader(rawCfg), file)
if err := os.WriteFile(configPath, buf.Bytes(), 0o755); err != nil {
return fmt.Errorf("config file migration failed: %w", err)
}
}

return nil
Expand Down