Skip to content

Commit

Permalink
fix: change config upgrade to avoid an empty config file on error (#3149
Browse files Browse the repository at this point in the history
)
  • Loading branch information
jeronimoalbi authored Nov 22, 2022
1 parent 6815bb1 commit 237cc1b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
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

0 comments on commit 237cc1b

Please sign in to comment.