From 5e5aeebea90ee1a911db4acd49015d36caaa4fb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Perdomo?= Date: Thu, 11 May 2017 08:57:53 +0200 Subject: [PATCH] [#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. --- leiningen-core/src/leiningen/core/utils.clj | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/leiningen-core/src/leiningen/core/utils.clj b/leiningen-core/src/leiningen/core/utils.clj index 4514ae79..c684e7b1 100644 --- a/leiningen-core/src/leiningen/core/utils.clj +++ b/leiningen-core/src/leiningen/core/utils.clj @@ -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."