From c3c0bf3cef75bed8857a0a205108a4c672ebd5cc Mon Sep 17 00:00:00 2001 From: Bob Date: Sat, 8 Jun 2024 14:56:07 -0400 Subject: [PATCH] catch exceptions from resolving symbolic links during `bb.edn` lookup (#1702) --- CHANGELOG.md | 1 + src/babashka/main.clj | 5 ++++- test/babashka/bb_edn_test.clj | 6 ++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9769e745..d38ba546 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ A preview of the next release can be installed from - [#1696](https://github.com/babashka/babashka/issues/1696): add `clojure.core/*source-path*` (points to the same sci var as `*file*`) ([@bobisageek](https://github.com/bobisageek)) - [#1696](https://github.com/babashka/babashka/issues/1696): add `clojure.main/with-read-known` ([@bobisageek](https://github.com/bobisageek)) - [#1696](https://github.com/babashka/babashka/issues/1696): add `clojure.core.server/repl-read` ([@bobisageek](https://github.com/bobisageek)) +- [#1700](https://github.com/babashka/babashka/issues/1700): catch exceptions from resolving symbolic links during `bb.edn` lookup ([@bobisageek](https://github.com/bobisageek)) ## 1.3.190 (2024-04-17) diff --git a/src/babashka/main.clj b/src/babashka/main.clj index 750d2f56..1a90c663 100644 --- a/src/babashka/main.clj +++ b/src/babashka/main.clj @@ -1149,7 +1149,10 @@ Use bb run --help to show this help output. (defn resolve-symbolic-link [f] (if (and f (fs/exists? f)) - (str (fs/real-path f)) + (try + (str (fs/real-path f)) + (catch Exception _ + f)) f)) (defn deps-not-needed [opts] diff --git a/test/babashka/bb_edn_test.clj b/test/babashka/bb_edn_test.clj index 1d778077..6d5868d9 100644 --- a/test/babashka/bb_edn_test.clj +++ b/test/babashka/bb_edn_test.clj @@ -531,6 +531,12 @@ even more stuff here\" (testing "symlink" (is (= {1 {:id 1}} (bb (str (fs/file "test-resources" "symlink-adjacent-bb"))))))) +; symlinks that resolve in the /proc fs cause fs/real-path to throw when figuring out bb.edn path (issue #1700) +(deftest redirection-test + (testing "main doesn't throw when input file symlink resolves to 'not real' file" + (when (and test-utils/native? (not test-utils/windows?)) + (is (str/starts-with? (test-utils/bb "(println \"hi\")" "/dev/stdin") "hi"))))) + (deftest non-existing-tasks-in-run-gives-exit-code-1 (is (thrown? Exception (bb "-Sdeps" "{:tasks {foo {:task (run (quote bar))}}}" "foo"))))