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

basilisp-lang / basilisp / 10948062695

19 Sep 2024 08:02PM CUT coverage: 98.89%. Remained the same
10948062695

push

github

web-flow
Fix a bug where the reader was double counting the CRLF newline seq (#1064)

Hi,

can you please a fix for the line number in the metadata generated by
the reader. It fixes #1063.

We now check the char at -2 only if it’s:
-  `\n` (for `\nC` or `\r\nC` case)
-  `\r` (for the `\rC`, but not `\r\n`, case).

where `C` is any other char.

Added tests for the same.

Thanks

---------

Co-authored-by: ikappaki <ikappaki@users.noreply.github.com>

1903 of 1910 branches covered (99.63%)

Branch coverage included in aggregate %.

1 of 1 new or added line in 1 file covered. (100.0%)

8695 of 8807 relevant lines covered (98.73%)

0.99 hits per line

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

93.1
/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 List, Optional, Type
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