Skip to content

Commit

Permalink
[wip] handle error early instead of nil-threading
Browse files Browse the repository at this point in the history
  • Loading branch information
caadr committed Nov 13, 2023
1 parent 5c1262a commit d7370f4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 31 deletions.
52 changes: 25 additions & 27 deletions cider-util.el
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ Any other value is just returned."

;;; Files
(defun cider--ensure-executable (file)
(with-demoted-errors "Error trying to make file executable:\n %s"
(with-demoted-errors "Error while trying to make file executable:\n %s"
(when (or (file-executable-p file)
(and (set-file-modes file "u+x")
(file-executable-p file)))
Expand All @@ -529,38 +529,36 @@ Any other value is just returned."
(concat ".cider__" (file-name-nondirectory file) "__")))

(defun cider--make-nearby-temp-copy (file)
(with-demoted-errors "Failed to copy to temporary file:\n %s"
(let* ((default-directory (or (clojure-project-dir) default-directory))
;; Note: (temporary-file-directory) uses `default-directory' as fallback.
(new-file (file-name-concat (temporary-file-directory)
(cider--make-temp-name file))))
(copy-file file new-file :exists-ok nil nil :keep-permissions)
new-file)))
(let* ((default-directory (or (clojure-project-dir) default-directory))
;; Note: (temporary-file-directory) uses `default-directory' as fallback.
(new-file (file-name-concat (temporary-file-directory)
(cider--make-temp-name file))))
(copy-file file new-file :exists-ok nil nil :keep-permissions)
new-file))

(defun cider--inject-self-delete (bash-script)
(with-demoted-errors "Failed to inject self-delete string:\n %s"
(let (;; Don't create any temporary files.
(remote-file-name-inhibit-locks t)
(remote-file-name-inhibit-auto-save-visited t)
(backup-inhibited t)
(auto-save-default nil)
;; Disable version-control check
(vc-handled-backends nil))
(with-temp-buffer
(insert-file-contents bash-script)
;; inject after the first line, assuming it is the shebang
(goto-char (point-min))
(skip-chars-forward "^\n")
(insert "\n")
(insert (format
"trap 'ARG=$?
(let (;; Don't create any temporary files.
(remote-file-name-inhibit-locks t)
(remote-file-name-inhibit-auto-save-visited t)
(backup-inhibited t)
(auto-save-default nil)
;; Disable version-control check
(vc-handled-backends nil))
(with-temp-buffer
(insert-file-contents bash-script)
;; inject after the first line, assuming it is the shebang
(goto-char (point-min))
(skip-chars-forward "^\n")
(insert "\n")
(insert (format
"trap 'ARG=$?
rm -v %s
echo \"cider: Cleaned up temporary script after use.\"
exit $ARG
' EXIT"
(file-local-name bash-script)))
(write-file bash-script))
bash-script)))
(file-local-name bash-script)))
(write-file bash-script))
bash-script))


;;; Help mode
Expand Down
9 changes: 5 additions & 4 deletions cider.el
Original file line number Diff line number Diff line change
Expand Up @@ -438,10 +438,11 @@ use. The search for <remote-tempdir> is handled by tramp and falls back to
(location (concat cider-dir name))
(script (cider--ensure-executable location)))
(if (file-remote-p default-directory)
(thread-first
(cider--make-nearby-temp-copy script)
(cider--ensure-executable)
(cider--inject-self-delete))
(with-demoted-errors "cider: Failed to init enrich-classpath on remote: %s"
(thread-first
(cider--make-nearby-temp-copy script)
(cider--ensure-executable)
(cider--inject-self-delete)))
script)))

(defun cider--jack-in-resolve-command-enrich (project-type)
Expand Down

0 comments on commit d7370f4

Please sign in to comment.