Skip to content

Commit 96a3eeb

Browse files
committed
Add message to when config failed to be parsed.
1 parent 139e475 commit 96a3eeb

File tree

3 files changed

+37
-9
lines changed

3 files changed

+37
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Unreleased
44

55
- Improve anthropic extraPayload requirement when adding models.
6+
- Add message to when config failed to be parsed.
67

78
## 0.40.0
89

src/eca/config.clj

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,25 @@
66
3. local config-file: searching from a local `.eca/config.json` file.
77
4. `initializatonOptions` sent in `initialize` request."
88
(:require
9+
[camel-snake-kebab.core :as csk]
910
[cheshire.core :as json]
1011
[cheshire.factory :as json.factory]
1112
[clojure.core.memoize :as memoize]
1213
[clojure.java.io :as io]
1314
[clojure.string :as string]
1415
[eca.logger :as logger]
15-
[eca.shared :as shared]
16-
[camel-snake-kebab.core :as csk])
16+
[eca.shared :as shared])
1717
(:import
1818
[java.io File]))
1919

2020
(set! *warn-on-reflection* true)
2121

22+
(def ^:private logger-tag "[CONFIG]")
23+
24+
(def ^:dynamic *env-var-config-error* false)
25+
(def ^:dynamic *global-config-error* false)
26+
(def ^:dynamic *local-config-error* false)
27+
2228
(def initial-config
2329
{:providers {"openai" {:api "openai-responses"
2430
:url "https://api.openai.com"
@@ -74,17 +80,19 @@
7480

7581
(def ^:private ttl-cache-config-ms 5000)
7682

77-
(defn ^:private safe-read-json-string [raw-string]
83+
(defn ^:private safe-read-json-string [raw-string config-dyn-var]
7884
(try
85+
(alter-var-root config-dyn-var (constantly false))
7986
(binding [json.factory/*json-factory* (json.factory/make-json-factory
8087
{:allow-comments true})]
8188
(json/parse-string raw-string))
8289
(catch Exception e
83-
(logger/warn "Error parsing config json:" (.getMessage e)))))
90+
(alter-var-root config-dyn-var (constantly true))
91+
(logger/warn logger-tag "Error parsing config json:" (.getMessage e)))))
8492

8593
(defn ^:private config-from-envvar* []
8694
(some-> (System/getenv "ECA_CONFIG")
87-
(safe-read-json-string)))
95+
(safe-read-json-string (var *env-var-config-error*))))
8896

8997
(def ^:private config-from-envvar (memoize config-from-envvar*))
9098

@@ -96,7 +104,7 @@
96104
(defn ^:private config-from-global-file* []
97105
(let [config-file (io/file (global-config-dir) "config.json")]
98106
(when (.exists config-file)
99-
(safe-read-json-string (slurp config-file)))))
107+
(safe-read-json-string (slurp config-file) (var *global-config-error*)))))
100108

101109
(def ^:private config-from-global-file (memoize/ttl config-from-global-file* :ttl/threshold ttl-cache-config-ms))
102110

@@ -107,7 +115,7 @@
107115
final-config
108116
(let [config-file (io/file (shared/uri->filename uri) ".eca" "config.json")]
109117
(when (.exists config-file)
110-
(safe-read-json-string (slurp config-file))))))
118+
(safe-read-json-string (slurp config-file) (var *local-config-error*))))))
111119
{}
112120
roots))
113121

@@ -193,3 +201,12 @@
193201
(when-not pure-config? (config-from-envvar))
194202
(when-not pure-config? (config-from-global-file))
195203
(when-not pure-config? (config-from-local-file (:workspace-folders db))))))))
204+
205+
(defn validation-error []
206+
(cond
207+
*env-var-config-error* "ENV"
208+
*global-config-error* "global"
209+
*local-config-error* "local"
210+
211+
;; all good
212+
:else nil))

src/eca/handlers.clj

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
[eca.features.tools.mcp :as f.mcp]
1010
[eca.llm-api :as llm-api]
1111
[eca.logger :as logger]
12+
[eca.messenger :as messenger]
1213
[eca.models :as models]
1314
[eca.shared :as shared]))
1415

@@ -49,19 +50,28 @@
4950
ollama-models)]
5051
(swap! db* update :models merge models))))
5152

52-
(defn initialize [{:keys [db*]} params]
53+
(defn initialize [{:keys [db* messenger]} params]
5354
(logger/logging-task
5455
:eca/initialize
5556
(reset! config/initialization-config* (shared/map->camel-cased-map (:initialization-options params)))
5657
(let [config (config/all @db*)]
57-
(logger/debug "Considered config: " config)
5858
(swap! db* assoc
5959
:client-info (:client-info params)
6060
:workspace-folders (:workspace-folders params)
6161
:client-capabilities (:capabilities params))
6262
(initialize-models! db* config)
6363
(when-not (:pureConfig config)
6464
(db/load-db-from-cache! db*))
65+
(future
66+
(Thread/sleep 1000) ;; wait chat window is open in some editors.
67+
(when-let [error (config/validation-error)]
68+
(messenger/chat-content-received
69+
messenger
70+
{:role "system"
71+
:content {:type :text
72+
:text (format "\nFailed to parse '%s' config, check stderr logs, double check your config and restart\n"
73+
error)}})))
74+
(logger/debug "Considered config: " config)
6575
{:models (sort (keys (:models @db*)))
6676
:chat-default-model (f.chat/default-model @db* config)
6777
:chat-behaviors (:chat-behaviors @db*)

0 commit comments

Comments
 (0)