fix: Don't crash on invalid config import

Currently if you pass a bogus JSON file to the `config import` command,
you get a nil deref.

Detect this and fail with a helpful error message instead.
This commit is contained in:
Brendan Jackman 2025-12-27 18:11:27 +01:00
parent f89975603e
commit 46ea0b79ff

View File

@ -53,6 +53,10 @@ The path must be for a json or yaml file.`,
return err
}
if file.Settings == nil || file.Server == nil {
return errors.New("invalid configuration file: 'settings' or 'server' fields are missing. Please ensure you are importing a file generated by the 'config export' command")
}
file.Settings.Key = key
err = st.Settings.Save(file.Settings)
if err != nil {