sci icon indicating copy to clipboard operation
sci copied to clipboard

Improve error message when recurring from try

Open MrGung opened this issue 3 years ago • 3 comments

0.7.4 Windows

With 0.7.4 I get

----- Error --------------------------------------------------------------------
Type:     clojure.lang.ExceptionInfo
Message:  Can only recur from tail position
Location: d:\Users\Steffen\bin\browsers.clj:14:11
Phase:    analysis

----- Context ------------------------------------------------------------------
10:         (println "trying" (str/join " " cmd))
11:         (println (apply shell/sh (browser url))))
12:       (catch java.io.IOException exc
13:         (if (seq browsers)
14:           (recur browsers)))
              ^--- Can only recur from tail position
15:       (catch Exception exc (println exc)))))

executing

(let [browsers [#(identity ["C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe" %])
                #(identity ["C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe" %])
                #(identity ["start" (str "microsoft-edge:" %)])
                #(identity ["C:\\Windows\\System32\\cmd.exe" "/c" "start" "shell:AppsFolder\\Microsoft.MicrosoftEdge_8wekyb3d8bbwe!MicrosoftEdge" %])
                #(identity ["C:\\Program Files\\Internet Explorer\\iexplore.exe" %])]
      url (first *command-line-args*)]
  (loop [[browser & browsers] browsers]
    (try
      (let [cmd (browser url)]
        (println "trying" (str/join " " cmd))
        (println (apply shell/sh (browser url))))
      (catch java.io.IOException exc
        (if (seq browsers)
          (recur browsers)))
      (catch Exception exc (println exc)))))

This worked previously and I'd think the recur actually is in tail position - I am not sure about the try, though.

MrGung avatar Feb 11 '22 09:02 MrGung

@MrGung The error message could be improved but the official Clojure would say: cannot recur across try.

borkdude avatar Feb 11 '22 09:02 borkdude

Oh my. Still - that changed between 0.7.3 and 0.7.4.

I'll fix my code...

MrGung avatar Feb 11 '22 09:02 MrGung

@MrGung It was accidentally supported since there was no check here, but it wasn't intentionally supported.

borkdude avatar Feb 11 '22 09:02 borkdude