Open kpodsiad opened 2 years ago
Easy workaround for this issue - fansi.Str(<string with ansi styles>, ErrorMode.Strip)
.
I got same kind of exception message
java.lang.IllegalArgumentException: Unknown ansi-escape [0;93m at index 16 inside string cannot be parsed into an fansi.Str
when trying to run command ssh-ping -q -W 2 -c 1 -p 22 myhost
with os.proc(...)
which is part of os.lib.
I was using Ubuntu 20.04, Ammonite Repl 2.4.0 (Scala 2.12.13 Java 11.0.18)
See this how to reproduce the error
EDIT:
I also tested this with Scala standard REPL and Ammonite REPL
Using ammonite REPL command fails
amm
Loading...
Welcome to the Ammonite Repl 2.4.0 (Scala 2.12.13 Java 11.0.18)
jk-kptmp@ import scala.sys.process._
import scala.sys.process._
jk-kptmp@ val res = "ssh-ping -q -W 2 -c 1 -p 22 myhost".!!
java.lang.IllegalArgumentException: Unknown ansi-escape [0;93m at index 19 inside string cannot be parsed into an fansi.Str
fansi.ErrorMode$Throw$.handle(Fansi.scala:419)
fansi.ErrorMode$Throw$.handle(Fansi.scala:407)
fansi.Str$.apply(Fansi.scala:272)
fansi.Str$.implicitApply(Fansi.scala:227)
pprint.Renderer.$anonfun$rec$33(Renderer.scala:149)
pprint.Result$.fromString(Result.scala:53)
pprint.Renderer.rec(Renderer.scala:149)
pprint.PPrinter.tokenize(PPrinter.scala:104)
ammonite.repl.FullReplAPI$Internal.print(FullReplAPI.scala:106)
ammonite.repl.FullReplAPI$Internal.print$(FullReplAPI.scala:61)
ammonite.repl.FullReplAPI$$anon$1.print(FullReplAPI.scala:34)
But when using scala REPL command executes without failures
scala
Welcome to Scala 2.12.8 (OpenJDK 64-Bit Server VM, Java 11.0.18).
Type in expressions for evaluation. Or try :help.
scala> import scala.sys.process._
import scala.sys.process._
scala> val res = "ssh-ping -q -W 2 -c 1 -p 22 myhost".!!
res: String =
"SSHPING myhost
--- myhost ping statistics ---
1 requests transmitted, 0 requests received, 100% request loss
"
scala>
Running the command in Ubuntu MATE terminal the output is
ssh-ping -q -W 2 -c 1 -p 22 myhost
SSHPING myhost
--- myhost ping statistics ---
1 requests transmitted, 0 requests received, 100% request loss
Summary
One of the Metals users hit an issue when Metals wasn't displaying errors which came from ZIO test suite. After an investigation I found that issue is caused by Fansi. ZIO sets various ansi styles in their tests and at least one of them (Faint -
"\u001b[2m"
) is unsupported by Fansi:In Metals, we use Fansi to obtain plain text from bsp diagnostic before forwarding it to the lsp client.
Reproduction
Behavior
Expected Behavior
Fansi should parse
\u001b[2m
ansi code, as well as other styles defined in linked file from ZIO repository.