Report configuration persistence failures

This commit is contained in:
Brandon McGinty (chatgpt) authored and Brandon McGinty committed 2026-08-10 11:25:08 -04:00
1 parent 655a109ce8
commit ef8a92149d
3 files changed
+27 -12

No files matched your search

+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())
}
}