Skip to content

Exception string output no longer includes type in Basilisp 0.4.0 #1271

@ikappaki

Description

@ikappaki

Hi,

I've noticed a change in how exceptions are printed in Basilisp 0.4.0 compared to 0.3.8: the exception type is no longer included when converting an exception to a string.

in 0.3.8:

> basilisp version
Basilisp 0.3.8
> basilisp repl
basilisp.user=> (str (Exception "abc"))
"Exception('abc')"

in 0.4.0:

> basilisp version
Basilisp 0.4.0
> (str (Exception "abc"))
"abc"

I believe this change is most likely related to #1238.

The new behavior aligns more closely with Python's str behavior:

python
Python 3.11.4 (tags/v3.11.4:d2340ef, Jun  7 2023, 05:45:37) [MSC v.1934 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> str(Exception("abc"))
'abc'
>>> repr(Exception("abc"))
"Exception('abc')"

However, it now diverges from Clojure’s behavior:

> clj
Clojure 1.12.0
user=> (str (Exception. "abc"))
"java.lang.Exception: abc"

Personally, I find Clojure’s approach more informative, it makes it clearer that you're looking at an exception, not just a plain string. That context can be important when debugging or logging.

If this change is intentional to match Python, it might be worth documenting in the Python differences section, since it changes how exception objects communicate intent in logs and output? Happy to update the documentation.

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions