Report configuration persistence failures

This commit is contained in:
Brandon McGinty (chatgpt)
2026-08-10 11:25:08 -04:00
committed by Brandon McGinty
parent 655a109ce8
commit ef8a92149d
3 changed files with 27 additions and 12 deletions
+7 -4
View File
@@ -58,6 +58,9 @@ func (c *Config) SaveConfig() error {
}
func (c *Config) saveConfigLocked() error {
if err := os.MkdirAll(filepath.Dir(c.fn), 0700); err != nil {
return err
}
data, err := toml.Marshal(c.config)
if err != nil {
return err
@@ -286,13 +289,13 @@ func (c *Config) findUser(address string, username string) *eUser {
return t
}
func (c *Config) ToggleMute(u *gumble.User) {
func (c *Config) ToggleMute(u *gumble.User) error {
c.mu.Lock()
defer c.mu.Unlock()
j := c.findUser(u.GetClient().Config.Address, u.Name)
j.LocallyMuted = !j.LocallyMuted
u.SetLocallyMuted(j.LocallyMuted)
_ = c.saveConfigLocked()
return c.saveConfigLocked()
}
func (c *Config) SetMicVolume(v float32) {
@@ -355,11 +358,11 @@ func (c *Config) GetNoiseSuppressionEnabled() bool {
return *c.config.NoiseSuppressionEnabled
}
func (c *Config) SetNoiseSuppressionEnabled(enabled bool) {
func (c *Config) SetNoiseSuppressionEnabled(enabled bool) error {
c.mu.Lock()
defer c.mu.Unlock()
c.config.NoiseSuppressionEnabled = &enabled
_ = c.saveConfigLocked()
return c.saveConfigLocked()
}
func (c *Config) GetRecordingFormat() string {
+12 -6
View File
@@ -7,13 +7,19 @@ import (
"testing"
)
// Regression: a configuration write failure panicked the client instead of
// returning an error to the caller.
func TestSaveConfigReturnsWriteError(t *testing.T) {
path := filepath.Join(t.TempDir(), "missing", "barnard.toml")
func TestSaveConfigCreatesMissingParentDirectory(t *testing.T) {
parent := filepath.Join(t.TempDir(), "missing")
path := filepath.Join(parent, "barnard.toml")
cfg := NewConfig(&path)
if err := cfg.SaveConfig(); err == nil {
t.Fatal("expected configuration write error")
if err := cfg.SaveConfig(); err != nil {
t.Fatal(err)
}
info, err := os.Stat(parent)
if err != nil {
t.Fatal(err)
}
if info.Mode().Perm()&0077 != 0 {
t.Fatalf("parent directory permissions = %o, want no group or other access", info.Mode().Perm())
}
}
+8 -2
View File
@@ -253,13 +253,19 @@ func main() {
b.Config.DisableUDP = *tcpOnly
b.Hotkeys = b.UserConfig.GetHotkeys()
b.UserConfig.SaveConfig()
if err := b.UserConfig.SaveConfig(); err != nil {
fmt.Fprintf(os.Stderr, "could not save configuration: %s\n", err)
os.Exit(1)
}
// Configure noise suppression
enabled := b.UserConfig.GetNoiseSuppressionEnabled()
if *noiseSuppressionEnabled {
enabled = true
b.UserConfig.SetNoiseSuppressionEnabled(true)
if err := b.UserConfig.SetNoiseSuppressionEnabled(true); err != nil {
fmt.Fprintf(os.Stderr, "could not save configuration: %s\n", err)
os.Exit(1)
}
}
b.NoiseSuppressor.SetEnabled(enabled)