|
6 | 6 | 3. local config-file: searching from a local `.eca/config.json` file. |
7 | 7 | 4. `initializatonOptions` sent in `initialize` request." |
8 | 8 | (:require |
| 9 | + [camel-snake-kebab.core :as csk] |
9 | 10 | [cheshire.core :as json] |
10 | 11 | [cheshire.factory :as json.factory] |
11 | 12 | [clojure.core.memoize :as memoize] |
12 | 13 | [clojure.java.io :as io] |
13 | 14 | [clojure.string :as string] |
14 | 15 | [eca.logger :as logger] |
15 | | - [eca.shared :as shared] |
16 | | - [camel-snake-kebab.core :as csk]) |
| 16 | + [eca.shared :as shared]) |
17 | 17 | (:import |
18 | 18 | [java.io File])) |
19 | 19 |
|
20 | 20 | (set! *warn-on-reflection* true) |
21 | 21 |
|
| 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 | + |
22 | 28 | (def initial-config |
23 | 29 | {:providers {"openai" {:api "openai-responses" |
24 | 30 | :url "https://api.openai.com" |
|
74 | 80 |
|
75 | 81 | (def ^:private ttl-cache-config-ms 5000) |
76 | 82 |
|
77 | | -(defn ^:private safe-read-json-string [raw-string] |
| 83 | +(defn ^:private safe-read-json-string [raw-string config-dyn-var] |
78 | 84 | (try |
| 85 | + (alter-var-root config-dyn-var (constantly false)) |
79 | 86 | (binding [json.factory/*json-factory* (json.factory/make-json-factory |
80 | 87 | {:allow-comments true})] |
81 | 88 | (json/parse-string raw-string)) |
82 | 89 | (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))))) |
84 | 92 |
|
85 | 93 | (defn ^:private config-from-envvar* [] |
86 | 94 | (some-> (System/getenv "ECA_CONFIG") |
87 | | - (safe-read-json-string))) |
| 95 | + (safe-read-json-string (var *env-var-config-error*)))) |
88 | 96 |
|
89 | 97 | (def ^:private config-from-envvar (memoize config-from-envvar*)) |
90 | 98 |
|
|
96 | 104 | (defn ^:private config-from-global-file* [] |
97 | 105 | (let [config-file (io/file (global-config-dir) "config.json")] |
98 | 106 | (when (.exists config-file) |
99 | | - (safe-read-json-string (slurp config-file))))) |
| 107 | + (safe-read-json-string (slurp config-file) (var *global-config-error*))))) |
100 | 108 |
|
101 | 109 | (def ^:private config-from-global-file (memoize/ttl config-from-global-file* :ttl/threshold ttl-cache-config-ms)) |
102 | 110 |
|
|
107 | 115 | final-config |
108 | 116 | (let [config-file (io/file (shared/uri->filename uri) ".eca" "config.json")] |
109 | 117 | (when (.exists config-file) |
110 | | - (safe-read-json-string (slurp config-file)))))) |
| 118 | + (safe-read-json-string (slurp config-file) (var *local-config-error*)))))) |
111 | 119 | {} |
112 | 120 | roots)) |
113 | 121 |
|
|
193 | 201 | (when-not pure-config? (config-from-envvar)) |
194 | 202 | (when-not pure-config? (config-from-global-file)) |
195 | 203 | (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)) |
0 commit comments