[#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:
parent
ae9ae4825d
commit
5e5aeebea9
1 changed files with 8 additions and 5 deletions
|
@ -1,7 +1,6 @@
|
||||||
(ns leiningen.core.utils
|
(ns leiningen.core.utils
|
||||||
(:require [clojure.java.io :as io]
|
(:require [clojure.java.io :as io]
|
||||||
[clojure.java.shell :as sh]
|
[clojure.java.shell :as sh])
|
||||||
[clojure.edn :as edn])
|
|
||||||
(:import (com.hypirion.io RevivableInputStream)
|
(:import (com.hypirion.io RevivableInputStream)
|
||||||
(clojure.lang LineNumberingPushbackReader)
|
(clojure.lang LineNumberingPushbackReader)
|
||||||
(java.io ByteArrayOutputStream PrintStream File FileDescriptor
|
(java.io ByteArrayOutputStream PrintStream File FileDescriptor
|
||||||
|
@ -41,14 +40,18 @@
|
||||||
"Returns the first Clojure form in a file if it exists."
|
"Returns the first Clojure form in a file if it exists."
|
||||||
[file]
|
[file]
|
||||||
(if (.exists file)
|
(if (.exists file)
|
||||||
(try (edn/read-string (slurp file))
|
(try (read-string (slurp file))
|
||||||
(catch Exception e
|
(catch Exception e
|
||||||
(binding [*out* *err*] ;; TODO: use main/warn for this in 3.0
|
(binding [*out* *err*] ;; TODO: use main/warn for this in 3.0
|
||||||
(println "Error reading"
|
(println "Error reading"
|
||||||
(.getName file)
|
(.getName file)
|
||||||
"from"
|
"from"
|
||||||
(.getParent file)))
|
(.getParent file))
|
||||||
(throw e)))))
|
(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?
|
(defn symlink?
|
||||||
"Checks if a File is a symbolic link or points to another file."
|
"Checks if a File is a symbolic link or points to another file."
|
||||||
|
|
Loading…
Reference in a new issue