Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected behavior using with-out-str with print-error-report #300

Closed
alpox opened this issue Jan 13, 2023 · 2 comments
Closed

Unexpected behavior using with-out-str with print-error-report #300

alpox opened this issue Jan 13, 2023 · 2 comments

Comments

@alpox
Copy link

alpox commented Jan 13, 2023

version

1.2.159

platform

macOS Ventura 13.1
Node v18.12.1

problem

When using the new error reporting function print-error-report with with-out-str I get back an empty string and the error report still writes to the original output. E.g.:

(with-out-str (print-error-report e))

Results in an empty string.

repro

(def result
  (try 
    (assoc :foo :bar)
    (catch ^:sci/error js/Error e
      (with-out-str (print-error-report e)))))

(prn result)

The above code prints an empty string.

expected behavior

The code in repro should print the actual error message stored in result.

@borkdude
Copy link
Collaborator

Publishing as 1.2.160. The way to do this now is to capture the output of *print-err-fn*:

(require '[nbb.error :refer [print-error-report]]
         '[clojure.string :as str])

(def result
  (try
    (assoc :foo :bar)
    (catch ^:sci/error js/Error e
      (let [lines (atom [])]
        (binding [*print-err-fn* #(swap! lines conj %)]
          (print-error-report e))
        (str/join "\n" @lines)))))

(println "Error:")
(println result)

@alpox
Copy link
Author

alpox commented Jan 13, 2023

Awesome. Thanks a lot again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants