From ded049b905555a0309eab1fce060333152050013 Mon Sep 17 00:00:00 2001 From: Stavros Kois <47820033+stavros-k@users.noreply.github.com> Date: Fri, 4 Jul 2025 15:58:17 +0300 Subject: [PATCH] don't crash if config file is missing (#2656) --- CHANGELOG.md | 2 ++ hscontrol/types/config.go | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 65518f39..aea84949 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,8 @@ [#2046](https://github.com/juanfont/headscale/pull/2046) - Refactor OpenID Connect documentation [#2625](https://github.com/juanfont/headscale/pull/2625) +- Don't crash if config file is missing + [#2656](https://github.com/juanfont/headscale/pull/2656) ## 0.26.1 (2025-06-06) diff --git a/hscontrol/types/config.go b/hscontrol/types/config.go index 09e6f818..baf8f264 100644 --- a/hscontrol/types/config.go +++ b/hscontrol/types/config.go @@ -335,6 +335,10 @@ func LoadConfig(path string, isFile bool) error { viper.SetDefault("prefixes.allocation", string(IPAllocationStrategySequential)) if err := viper.ReadInConfig(); err != nil { + if errors.Is(err, fs.ErrNotExist) { + log.Warn().Msg("No config file found, using defaults") + return nil + } return fmt.Errorf("fatal error reading config file: %w", err) }