Instrument to debug failure in file/alter-file

Also create a fn to handle uncertain global-config-dir paths.
Follow up to 24975cda01
pull/6967/head
Gabriel Horner 2022-10-12 15:34:50 -04:00
parent da35064b32
commit 2386cbe254
3 changed files with 36 additions and 19 deletions

View File

@ -98,8 +98,9 @@
#(p/resolved nil)
#(let [path-dir (if (and
(config/global-config-enabled?)
(global-config-handler/global-config-dir)
(= (path/dirname path) (global-config-handler/global-config-dir)))
;; Hack until we better understand failure in error handler
(global-config-handler/global-config-dir-exists?)
(= (path/dirname path) (global-config-handler/global-config-dir)))
(global-config-handler/global-config-dir)
(config/get-repo-dir repo))]
(fs/write-file! repo path-dir path content
@ -136,13 +137,22 @@
(state/pub-event! [:shortcut/refresh]))))
(fn [error]
(when (and (config/global-config-enabled?)
;; Global-config not started correctly but don't
;; know root cause yet
;; https://sentry.io/organizations/logseq/issues/3587411237/events/4b5da8b8e58b4f929bd9e43562213d32/events/?cursor=0%3A0%3A1&project=5311485&statsPeriod=14d
(global-config-handler/global-config-dir-exists?)
(= path (global-config-handler/global-config-path)))
(state/pub-event! [:notification/show
{:content (str "Failed to write to file " path)
:status :error}]))
{:content (str "Failed to write to file " path)
:status :error}]))
(println "Write file failed, path: " path ", content: " content)
(log/error :write/failed error)))
(log/error :write/failed error)
(state/pub-event! [:instrument {:type :write-file/failed-for-alter-file
:payload {:path path
:content-length (count content)
:error-str (str error)
:error error}}])))
result))
(defn set-file-content!

View File

@ -16,13 +16,19 @@
(defonce root-dir
(atom nil))
(defn global-config-dir-exists?
"This is used in contexts where we are unusure whether global-config has been
started correctly e.g. an error handler"
[]
(some? @root-dir))
(defn global-config-dir
[]
(when @root-dir (path/join @root-dir "config")))
(path/join @root-dir "config"))
(defn global-config-path
[]
(when @root-dir (path/join @root-dir "config" "config.edn")))
(path/join @root-dir "config" "config.edn"))
(defn- set-global-config-state!
[content]
@ -34,21 +40,21 @@
(defn- create-global-config-file-if-not-exists
[repo-url]
(when-let [config-dir (global-config-dir)]
(let [config-path (global-config-path)]
(p/let [_ (fs/mkdir-if-not-exists config-dir)
file-exists? (fs/create-if-not-exists repo-url config-dir config-path default-content)]
(when-not file-exists?
(file-common-handler/reset-file! repo-url config-path default-content)
(set-global-config-state! default-content))))))
(let [config-dir (global-config-dir)
config-path (global-config-path)]
(p/let [_ (fs/mkdir-if-not-exists config-dir)
file-exists? (fs/create-if-not-exists repo-url config-dir config-path default-content)]
(when-not file-exists?
(file-common-handler/reset-file! repo-url config-path default-content)
(set-global-config-state! default-content)))))
(defn restore-global-config!
"Sets global config state from config file"
[]
(when-let [config-dir (global-config-dir)]
(let [config-path (global-config-path)]
(p/let [config-content (fs/read-file config-dir config-path)]
(set-global-config-state! config-content)))))
(let [config-dir (global-config-dir)
config-path (global-config-path)]
(p/let [config-content (fs/read-file config-dir config-path)]
(set-global-config-state! config-content))))
(defn start
"This component has four responsibilities on start:

View File

@ -342,7 +342,8 @@
new-local-files (-> (->db-files mobile-native? electron? dir-name local-files-result)
(remove-ignore-files dir-name nfs?))
new-global-files (if (and (config/global-config-enabled?)
(global-config-handler/global-config-dir))
;; Hack until we better understand failure in frontend.handler.file/alter-file
(global-config-handler/global-config-dir-exists?))
(p/let [global-files-result (fs/get-files
(global-config-handler/global-config-dir)
(constantly nil))