From f06f962d84c40718528e4e908d73c13e7d8fe774 Mon Sep 17 00:00:00 2001 From: Jannis Mattheis Date: Wed, 15 Jul 2026 19:59:18 +0200 Subject: [PATCH] fix: error when legacy config exists --- config/config_test.go | 12 ++++++++++++ config/file.go | 13 +++++++++++++ 2 files changed, 25 insertions(+) diff --git a/config/config_test.go b/config/config_test.go index 216d80789..39d536479 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -74,6 +74,18 @@ func TestGotifyConfigFile(t *testing.T) { assert.Equal(t, "fromfile", conf.DefaultUser.Name) } +func TestLegacyConfigFile(t *testing.T) { + mode.Set(mode.TestDev) + dir := t.TempDir() + assert.NoError(t, os.WriteFile(filepath.Join(dir, "config.yml"), []byte(""), 0o600)) + t.Chdir(dir) + + _, logs := Get() + + assert.Len(t, logs, 1) + assert.Contains(t, logs[0].Msg, "the YAML config file is no longer supported. Convert it with 'gotify-server migrate-config") +} + func TestAddSlash(t *testing.T) { mode.Set(mode.TestDev) os.Setenv("GOTIFY_UPLOADEDIMAGESDIR", "../data/images") diff --git a/config/file.go b/config/file.go index 9479cfd0f..5380f7283 100644 --- a/config/file.go +++ b/config/file.go @@ -11,7 +11,20 @@ import ( var osStat = os.Stat +func checkLegacyConfigFiles() error { + for _, file := range []string{"config.yml", "/etc/gotify/config.yml"} { + if _, err := osStat(file); err == nil { + return fmt.Errorf("found %s, the YAML config file is no longer supported. Convert it with 'gotify-server migrate-config %s', see https://gotify.net/docs/migrate-to-3", file, file) + } + } + return nil +} + func loadFiles() []FutureLog { + if err := checkLegacyConfigFiles(); err != nil { + return []FutureLog{futureFatal(err.Error())} + } + if configFile := os.Getenv("GOTIFY_CONFIG_FILE"); configFile != "" { log, _ := loadFile(configFile) return []FutureLog{log}