mirror of https://github.com/logseq/logseq
fix: Improve error handling in `mkdir` function (#9247)
* Improve error handling in `mkdir-if-not-exists` function This PR improves the error handling in the `mkdir-if-not-exists` function by logging the "EEXIST" error (which indicates the directory already exists) instead of throwing it. Other errors will continue to be handled as before. - [x] closes #9182 * enhance: move error handling to fs/node.js * fix: make EEXIST silent and only throw other errorspull/9259/head
parent
abcc6c5bcf
commit
aebfae729f
|
@ -194,14 +194,12 @@
|
|||
|
||||
(defn mkdir-if-not-exists
|
||||
[dir]
|
||||
(->
|
||||
(when dir
|
||||
(util/p-handle
|
||||
(stat dir)
|
||||
(fn [_stat])
|
||||
(fn [_error]
|
||||
(mkdir! dir))))
|
||||
(p/catch (fn [error] (js/console.error error)))))
|
||||
(when dir
|
||||
(util/p-handle
|
||||
(stat dir)
|
||||
(fn [_stat])
|
||||
(fn [_error]
|
||||
(mkdir! dir)))))
|
||||
|
||||
;; FIXME: counterintuitive return value
|
||||
(defn create-if-not-exists
|
||||
|
|
|
@ -80,24 +80,33 @@
|
|||
(defrecord Node []
|
||||
protocol/Fs
|
||||
(mkdir! [_this dir]
|
||||
(ipc/ipc "mkdir" dir))
|
||||
(-> (ipc/ipc "mkdir" dir)
|
||||
(p/then (fn [_] (js/console.log (str "Directory created: " dir))))
|
||||
(p/catch (fn [error]
|
||||
(when (not= (.-code error) "EEXIST")
|
||||
(js/console.error (str "Error creating directory: " dir) error))))))
|
||||
|
||||
(mkdir-recur! [_this dir]
|
||||
(ipc/ipc "mkdir-recur" dir))
|
||||
|
||||
(readdir [_this dir] ; recursive
|
||||
(p/then (ipc/ipc "readdir" dir)
|
||||
bean/->clj))
|
||||
|
||||
(unlink! [_this repo path _opts]
|
||||
(ipc/ipc "unlink"
|
||||
(config/get-repo-dir repo)
|
||||
path))
|
||||
(rmdir! [_this _dir]
|
||||
;; Too dangerious!!! We'll never implement this.
|
||||
;; !Too dangerous! We'll never implement this.
|
||||
nil)
|
||||
|
||||
(read-file [_this dir path _options]
|
||||
(let [path (if (nil? dir)
|
||||
path
|
||||
(path/path-join dir path))]
|
||||
(ipc/ipc "readFile" path)))
|
||||
|
||||
(write-file! [this repo dir path content opts]
|
||||
(p/let [fpath (path/path-join dir path)
|
||||
stat (p/catch
|
||||
|
@ -106,18 +115,24 @@
|
|||
parent-dir (path/parent fpath)
|
||||
_ (protocol/mkdir-recur! this parent-dir)]
|
||||
(write-file-impl! repo dir path content opts stat)))
|
||||
|
||||
(rename! [_this _repo old-path new-path]
|
||||
(ipc/ipc "rename" old-path new-path))
|
||||
|
||||
(stat [_this fpath]
|
||||
(-> (ipc/ipc "stat" fpath)
|
||||
(p/then bean/->clj)))
|
||||
|
||||
(open-dir [_this dir]
|
||||
(open-dir dir))
|
||||
|
||||
(get-files [_this dir]
|
||||
(-> (ipc/ipc "getFiles" dir)
|
||||
(p/then (fn [result]
|
||||
(:files (bean/->clj result))))))
|
||||
|
||||
(watch-dir! [_this dir options]
|
||||
(ipc/ipc "addDirWatcher" dir options))
|
||||
|
||||
(unwatch-dir! [_this dir]
|
||||
(ipc/ipc "unwatchDir" dir)))
|
||||
|
|
Loading…
Reference in New Issue