babashka / bbin

Install any Babashka script or project with one command
MIT License
139 stars 9 forks source link

Work in process: try avoiding crash with `bbin uninstall` #71

Closed teodorlu closed 1 year ago

teodorlu commented 1 year ago

Problem: bbin uninstall myscript failed for a locally installed bbin script.

I was able to catch the exception that was raised in my specific case and delete the script in question. But it would be better do solve this in line with how the rest of the code works.


The script was installed with

$ bbin install . --as jals --main-opts '["-m" "mikrobloggeriet.jals-cli"]'

, executed from the script source folder.

I couldn't really follow the procurer logic. In my mind, deleting a locally installed script should just be to delete the shim/link to where the script was installed.

This work is based on the v0.1.13 tag.


Full repro, including the script I installed:

$ cd $(mktemp -d)
$ git clone git@github.com:iterate/mikrobloggeriet.git
Cloning into 'mikrobloggeriet'...
remote: Enumerating objects: 5559, done.
remote: Counting objects: 100% (1304/1304), done.
remote: Compressing objects: 100% (451/451), done.
remote: Total 5559 (delta 892), reused 1228 (delta 832), pack-reused 4255
Receiving objects: 100% (5559/5559), 708.09 KiB | 550.00 KiB/s, done.
Resolving deltas: 100% (2694/2694), done.
$ cd mikrobloggeriet 
$ git rev-parse HEAD
5c3807be34a23fd89fe9c82b067f1faa9392f869
$ bbin install . --as jals --main-opts '["-m" "mikrobloggeriet.jals-cli"]'

{:coords
 {:bbin/url
  "file:///private/var/folders/_s/yj6rk2hj0llgly4hrb906z4c0000gn/T/tmp.Jl0ptx71/mikrobloggeriet"}}
$ bbin uninstall jals
----- Error --------------------------------------------------------------------
Type:     clojure.lang.ExceptionInfo
Message:  Invalid script coordinates.
If you're trying to install from the filesystem, make sure the path actually exists.
Data:     {:script/lib "jals", :procurer :unknown-procurer, :artifact :unknown-artifact}
Location: /Users/teodorlu/.local/bin/bbin:1192:5

----- Context ------------------------------------------------------------------
1188:   (println (str (util/bin-dir cli-opts))))
1189: 
1190: (defn- throw-invalid-script [summary cli-opts]
1191:   (let [{:keys [procurer artifact]} summary]
1192:     (throw (ex-info "Invalid script coordinates.\nIf you're trying to install from the filesystem, make sure the path actually exists."
          ^--- Invalid script coordinates.
If you're trying to install from the filesystem, make sure the path actually exists.
1193:                     {:script/lib (:script/lib cli-opts)
1194:                      :procurer procurer
1195:                      :artifact artifact}))))
1196: 
1197: (defn- new-script [cli-opts]

----- Stack trace --------------------------------------------------------------
babashka.bbin.scripts/throw-invalid-script - /Users/teodorlu/.local/bin/bbin:1192:5
babashka.bbin.scripts/throw-invalid-script - /Users/teodorlu/.local/bin/bbin:1190:1
babashka.bbin.scripts/load-script          - /Users/teodorlu/.local/bin/bbin:1243:11
babashka.bbin.scripts/load-script          - /Users/teodorlu/.local/bin/bbin:1228:1
babashka.bbin.scripts                      - /Users/teodorlu/.local/bin/bbin:1273:20
... (run with --debug to see elided elements)
babashka.bbin.cli/bbin                     - /Users/teodorlu/.local/bin/bbin:1341:1
babashka.bbin.cli                          - /Users/teodorlu/.local/bin/bbin:1347:3
clojure.core/apply                         - <built-in>
babashka.bbin.cli                          - /Users/teodorlu/.local/bin/bbin:1351:3
babashka.bbin.cli                          - /Users/teodorlu/.local/bin/bbin:1349:1

$ bbin-dev uninstall jals

Here, bbin is bbin 0.1.13, and bbin-dev my branch.

teodorlu commented 1 year ago

👍