Error in CLI command caused deletion of entire config.toml
spacetime sql control-database "SELECT * FROM Node"
config file "/Users/tylercloutier/.spacetime/config.toml" is invalid: Error {
inner: Error {
inner: TomlError {
message: "duplicate key `identity` in table `identity_configs`",
original: Some(REDACTED BY TYLER BUT THIS WAS THE CONTENT OF THE FILE),
keys: [],
span: Some(
3092..3093,
),
},
},
}
Error: Cannot find protocol for default server
Caused by:
No default server configuration.
Set an existing server as the default with:
spacetime server set-default <server>
Or add a new server which will become the default:
spacetime server add <url> --default
After this error the config.toml file was just empty.
Context: This happened after a manual edit to the config.toml, which caused the CLI to treat the config as malformed due the duplicate identities mentioned in the error message.
Our CLI generally doesn't handle kindly any errors in the config file.
We discussed and we're assigning this to me to do a bit of research and propose something a little less jarring for users.
(Also, for the record, @gefjon points out correctly that as long as our CLI doesn't handle these cases well, we should really really discourage users from making any manual edits).
in the immediate term, we should probably do one or all of:
- if the config fails to parse, don't overwrite it; just use the default one "in-memory", and print a warning
- tell the user that we can't load their config, and prompt if they want to overwrite
- before we save the config file, copy the existing file to something like
config.toml.bak
That's probably easier than training all of the users to not manually modify their config files.
If we're going to allow or encourage users to edit their config files by hand, we should also look into preserving comments and formatting.