[#2272] Catch read-string exceptions and print a nicer error

* This is change in behavior, we catch the clojure.core/read-string
  exception and we print it to stderr. The difference is that we
  let the process continue (e.g. `lein repl` starts) and the previous
  behavior was to die (due to the throwing the exception)
* We could mimic the previous behavior by exiting (System/exit 1) on
  this exception.
This commit is contained in:
Iván Perdomo 2017-05-11 08:57:53 +02:00
parent ae9ae4825d
commit 5e5aeebea9
No known key found for this signature in database
GPG key ID: 8C915DFD250CF3EA

View file

@ -1,7 +1,6 @@
(ns leiningen.core.utils
(:require [clojure.java.io :as io]
[clojure.java.shell :as sh]
[clojure.edn :as edn])
[clojure.java.shell :as sh])
(:import (com.hypirion.io RevivableInputStream)
(clojure.lang LineNumberingPushbackReader)
(java.io ByteArrayOutputStream PrintStream File FileDescriptor
@ -41,14 +40,18 @@
"Returns the first Clojure form in a file if it exists."
[file]
(if (.exists file)
(try (edn/read-string (slurp file))
(try (read-string (slurp file))
(catch Exception e
(binding [*out* *err*] ;; TODO: use main/warn for this in 3.0
(println "Error reading"
(.getName file)
"from"
(.getParent file)))
(throw e)))))
(.getParent file))
(if (zero? (.length file))
(println "File cannot be empty")
(if (.contains (.getMessage e) "EOF while reading")
(println "Invalid content was found")
(println (.getMessage e)))))))))
(defn symlink?
"Checks if a File is a symbolic link or points to another file."