@@ -582,38 +582,36 @@ java -cp clojure.jar clojure.main -i init.clj script.clj args...")
582
582
(null-opt args (map vector (repeat " -i" ) inits))))
583
583
584
584
(defn report-error
585
- " Create and output an exception report for a Throwable to target,
586
- and optionally exit.
585
+ " Create and output an exception report for a Throwable to target.
587
586
588
587
Options:
589
- :target - either :temp-file or :stderr, default to :temp-file
590
- :exit - if set will System/exit with this code on err, default to 1
591
-
592
- If temp file is specified but cannot be completed, falls back to stderr."
593
- [^Throwable t & {:keys [target exit]
594
- :or {target :temp-file , exit 1 } :as opts}]
595
- (let [trace (Throwable->map t)
596
- triage (ex-triage trace)
597
- message (ex-str triage)
598
- report (array-map :clojure.main/message message
599
- :clojure.main/triage triage
600
- :clojure.main/trace trace)
601
- report-str (with-out-str
602
- (binding [*print-namespace-maps* false ]
603
- ((requiring-resolve 'clojure.pprint/pprint) report)))
604
- err-path (when (= target :temp-file )
605
- (try
606
- (let [f (.toFile (Files/createTempFile " clojure-" " .edn" (into-array FileAttribute [])))]
607
- (with-open [w (BufferedWriter. (FileWriter. f))]
608
- (binding [*out* w] (println report-str)))
609
- (.getAbsolutePath f))
610
- (catch Throwable _)))] ; ; ignore, fallback to stderr
611
- (binding [*out* *err*]
612
- (if err-path
613
- (println (str message (System/lineSeparator ) " Full report at:" (System/lineSeparator ) err-path))
614
- (println (str report-str (System/lineSeparator ) message))))
615
- (when exit
616
- (System/exit exit))))
588
+ :target - \" file\" (default), \" stderr\" , \" none\"
589
+
590
+ If file is specified but cannot be written, falls back to stderr."
591
+ [^Throwable t & {:keys [target]
592
+ :or {target " file" } :as opts}]
593
+ (when-not (= target " none" )
594
+ (let [trace (Throwable->map t)
595
+ triage (ex-triage trace)
596
+ message (ex-str triage)
597
+ report (array-map
598
+ :clojure.main/message message
599
+ :clojure.main/triage triage
600
+ :clojure.main/trace trace)
601
+ report-str (with-out-str
602
+ (binding [*print-namespace-maps* false ]
603
+ ((requiring-resolve 'clojure.pprint/pprint) report)))
604
+ err-path (when (= target " file" )
605
+ (try
606
+ (let [f (.toFile (Files/createTempFile " clojure-" " .edn" (into-array FileAttribute [])))]
607
+ (with-open [w (BufferedWriter. (FileWriter. f))]
608
+ (binding [*out* w] (println report-str)))
609
+ (.getAbsolutePath f))
610
+ (catch Throwable _)))] ; ; ignore, fallback to stderr
611
+ (binding [*out* *err*]
612
+ (if err-path
613
+ (println (str message (System/lineSeparator ) " Full report at:" (System/lineSeparator ) err-path))
614
+ (println (str report-str (System/lineSeparator ) message)))))))
617
615
618
616
(defn main
619
617
" Usage: java -cp clojure.jar clojure.main [init-opt*] [main-opt] [arg*]
@@ -623,7 +621,8 @@ java -cp clojure.jar clojure.main -i init.clj script.clj args...")
623
621
init options:
624
622
-i, --init path Load a file or resource
625
623
-e, --eval string Evaluate expressions in string; print non-nil values
626
- --report-stderr Print uncaught exception report to stderr
624
+ --report target Report uncaught exception to \" file\" (default), \" stderr\" ,
625
+ or \" none\" , overrides System property clojure.main.report
627
626
628
627
main options:
629
628
-m, --main ns-name Call the -main function from a namespace with args
@@ -653,8 +652,8 @@ java -cp clojure.jar clojure.main -i init.clj script.clj args...")
653
652
(loop [[opt arg & more :as args] args, inits [], flags nil ]
654
653
(cond
655
654
; ; flag
656
- (contains? #{" --report-stderr " } opt)
657
- (recur ( rest args) inits (merge flags {(subs opt 2 ) true }))
655
+ (contains? #{" --report" } opt)
656
+ (recur more inits (merge flags {(subs opt 2 ) arg }))
658
657
659
658
; ; init opt
660
659
(init-dispatch opt)
@@ -664,11 +663,13 @@ java -cp clojure.jar clojure.main -i init.clj script.clj args...")
664
663
(try
665
664
((main-dispatch opt) args inits)
666
665
(catch Throwable t
667
- (report-error t :target (if (contains? flags " report-stderr" ) :stderr :temp-file ))))))
666
+ (report-error t :target (get flags " report" (System/getProperty " clojure.main.report" " file" )))
667
+ (System/exit 1 )))))
668
668
(try
669
669
(repl-opt nil nil )
670
670
(catch Throwable t
671
- (report-error :target :temp-file ))))
671
+ (report-error t :target " file" )
672
+ (System/exit 1 ))))
672
673
(finally
673
674
(flush ))))
674
675
0 commit comments