summaryrefslogtreecommitdiff
path: root/cmd/hexai-lsp-server
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-10 19:35:58 +0200
committerPaul Buetow <paul@buetow.org>2026-03-10 19:35:58 +0200
commit07115c22a74dd5311f70434029791d5346e627c4 (patch)
tree9d1b951d7f8486baf46679163d04fd11049fd034 /cmd/hexai-lsp-server
parentde5029e6d4a7efffcccfb08d98770b1c1c4f54fe (diff)
task dac9b1e5: avoid LSP startup panic on StateDir failure
Diffstat (limited to 'cmd/hexai-lsp-server')
-rw-r--r--cmd/hexai-lsp-server/main.go7
-rw-r--r--cmd/hexai-lsp-server/main_test.go15
2 files changed, 18 insertions, 4 deletions
diff --git a/cmd/hexai-lsp-server/main.go b/cmd/hexai-lsp-server/main.go
index c8cdd8f..e3e458d 100644
--- a/cmd/hexai-lsp-server/main.go
+++ b/cmd/hexai-lsp-server/main.go
@@ -6,6 +6,7 @@ import (
"fmt"
"log"
"os"
+ "path/filepath"
"strings"
"codeberg.org/snonux/hexai/internal"
@@ -40,13 +41,11 @@ func defaultConfigPath() string {
}
// defaultLogPath returns the default LSP log file path in the state directory.
-// Falls back to /tmp if state directory cannot be determined.
-// defaultLogPath returns the default LSP log file path in the state directory.
-// Panics if state directory cannot be created.
+// Falls back to the system temp directory if the state directory is unavailable.
func defaultLogPath() string {
stateDir, err := appconfig.StateDir()
if err != nil {
- panic(fmt.Sprintf("cannot create state directory: %v", err))
+ return filepath.Join(os.TempDir(), "hexai-lsp-server.log")
}
return fmt.Sprintf("%s/hexai-lsp-server.log", stateDir)
}
diff --git a/cmd/hexai-lsp-server/main_test.go b/cmd/hexai-lsp-server/main_test.go
index 5563e3d..9861f54 100644
--- a/cmd/hexai-lsp-server/main_test.go
+++ b/cmd/hexai-lsp-server/main_test.go
@@ -4,6 +4,7 @@ import (
"bytes"
"log"
"os"
+ "path/filepath"
"testing"
)
@@ -20,3 +21,17 @@ func TestMain_Version(t *testing.T) {
t.Fatalf("expected version log")
}
}
+
+func TestDefaultLogPathFallsBackToTempDirOnStateDirFailure(t *testing.T) {
+ stateHome := filepath.Join(t.TempDir(), "state-home-file")
+ if err := os.WriteFile(stateHome, []byte("not-a-directory"), 0o644); err != nil {
+ t.Fatalf("write state home marker: %v", err)
+ }
+ t.Setenv("XDG_STATE_HOME", stateHome)
+
+ got := defaultLogPath()
+ want := filepath.Join(os.TempDir(), "hexai-lsp-server.log")
+ if got != want {
+ t.Fatalf("expected temp-dir fallback %q, got %q", want, got)
+ }
+}