Skip to content

nREPL server: ANSI Escape Codes in nREPL tracebacks #1039

Closed
@ikappaki

Description

The nREPL server's exception messages may include tracebacks containing ANSI color escape sequences, which can be nearly unreadable in editors that do not support ANSI colors in all contexts, such as the example below

image

To reproduce in Emacs in CIDER mode:

  1. Create a project with a user.lpy file with the following content with a commented out form that will throw a compiler exception if evaluated:
(ns user)

(comment
  (abc)
  ;;
  )
  1. Open the project in Emacs with CIDER, ensuring you are in a virtual environment with basilisp installed. Add an empty basilisp.edn file at the root of the project, then start the nREPL server using M-x cider-jack-in.
  2. Open the user.lpy file, go to the end of the (abc) line, and press C-x-e to evaluate the form. A compiler error will be thrown, but the traceback will be difficult to read due to the ANSI escape codes not being rendered properly
=> exception: <class 'basilisp.lang.compiler.exception.CompilerException'>
      phase: :analyzing
    message: unable to resolve symbol 'abc' in this context
       form: abc
   location: user.lpy:1
    context:

 1 > | (�[34mns �[39;49;00m�[31muser�[39;49;00m)�[37m�[39;49;00m
 2   | �[37m�[39;49;00m
 3   | (�[32mcomment�[39;49;00m�[37m�[39;49;00m
 4   | �[37m  �[39;49;00m(�[32mabc�[39;49;00m)�[37m�[39;49;00m
 5   | �[37m  �[39;49;00m�[37m;;�[39;49;00m�[37m�[39;49;00m
 6   | �[37m  �[39;49;00m)�[37m�[39;49;00m

While it's possible to patch CIDER to strip ANSI characters in unsupported areas, I believe it's preferable to disable ANSI escape code generation in the Basilisp nREPL server. The nREPL server should not assume that all editor environments will properly render ANSI codes under all circumstances, so disabling them by default would improve readability across various editors.

PR to follow.

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