• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

basilisp-lang / basilisp / 12415756702

19 Dec 2024 03:30PM CUT coverage: 98.738%. Remained the same
12415756702

Pull #1187

github

web-flow
Merge 792584ba3 into f81b7b6fb
Pull Request #1187: Ensure `defn` metadata are always preserved as a map

1030 of 1037 branches covered (99.32%)

Branch coverage included in aggregate %.

8825 of 8944 relevant lines covered (98.67%)

0.99 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.59
/src/basilisp/lang/exception.py
1
import functools
1✔
2
import sys
1✔
3
import traceback
1✔
4
from types import TracebackType
1✔
5
from typing import Optional
1✔
6

7
import attr
1✔
8

9
from basilisp.lang.interfaces import IExceptionInfo, IPersistentMap
1✔
10
from basilisp.lang.obj import lrepr
1✔
11

12

13
@attr.define(repr=False, str=False)
1✔
14
class ExceptionInfo(IExceptionInfo):
1✔
15
    message: str
1✔
16
    data: IPersistentMap
1✔
17

18
    def __repr__(self):
19
        return (
20
            f"basilisp.lang.exception.ExceptionInfo({self.message}, {lrepr(self.data)})"
21
        )
22

23
    def __str__(self):
1✔
24
        return f"{self.message} {lrepr(self.data)}"
1✔
25

26

27
@functools.singledispatch
1✔
28
def format_exception(  # pylint: disable=unused-argument
1✔
29
    e: Optional[BaseException],
30
    tp: Optional[type[BaseException]] = None,
31
    tb: Optional[TracebackType] = None,
32
    disable_color: Optional[bool] = None,
33
) -> list[str]:
34
    """Format an exception into something readable, returning a list of newline
35
    terminated strings.
36

37
    For the majority of Python exceptions, this will just be the result from calling
38
    `traceback.format_exception`. For Basilisp specific compilation errors, a custom
39
    output will be returned.
40

41
    If `disable_color` is True, no color formatting should be applied to the source
42
    code."""
43
    if isinstance(e, BaseException):
1✔
44
        if tp is None:
1✔
45
            tp = type(e)
×
46
        if tb is None:
1✔
47
            tb = e.__traceback__
×
48
    return traceback.format_exception(tp, e, tb)
1✔
49

50

51
def print_exception(
1✔
52
    e: Optional[BaseException],
53
    tp: Optional[type[BaseException]] = None,
54
    tb: Optional[TracebackType] = None,
55
) -> None:
56
    """Print the given exception `e` using Basilisp's own exception formatting.
57

58
    For the majority of exception types, this should be identical to the base Python
59
    traceback formatting. `basilisp.lang.compiler.CompilerException` and
60
    `basilisp.lang.reader.SyntaxError` have special handling to print useful information
61
    on exceptions."""
62
    print("".join(format_exception(e, tp, tb)), file=sys.stderr)
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc