VirtusLab / besom

Besom - a Pulumi SDK for Scala. Also, incidentally, a broom made of twigs tied round a stick. Brooms and besoms are used for protection, to ward off evil spirits, and cleansing of ritual spaces.
https://virtuslab.github.io/besom/
Apache License 2.0
113 stars 7 forks source link

besom.internal.ResourceDecoder fails to parse some escape codes #489

Closed nikolaiser closed 1 month ago

nikolaiser commented 1 month ago
//> using scala "3.3.3"
//> using options -Werror -Wunused:all -Wvalue-discard -Wnonunit-statement
//> using dep "org.virtuslab::besom-core:0.3.1"
//> using dep "org.virtuslab::besom-command:0.10.0-core.0.3"
import besom.*
import besom.api.command

@main def main = Pulumi.run {

  val run = command.local.Command(
      "test-command",
      command.local.CommandArgs(
          create = """echo -e "normal text here \n\x1b[0;1;31m this text should be bold and red""""
        )
    )

  Stack.exports(
    stdout = run.stdout
  )
}

pulumi up fails with

 2024.05.07 00:02:40:797 scala-execution-context-global-52 [resource: test-command[command:local:Command]] ERROR besom.internal.ResourceDecoder.resolve:97
        Resolve resource: received error from gRPC call: 'Unknown ansi-escape [0;1;31m at index 21 inside string cannot be
        parsed into an fansi.Str', failing resolution
    2024.05.07 00:02:40:844 main  ERROR besom.internal.BesomModule.run:70
        java.lang.IllegalArgumentException: Unknown ansi-escape [0;1;31m at index 21 inside string cannot be parsed into an
         fansi.Str
lbialy commented 1 month ago

Thank you for this report! I'm wondering if this is hiding another issue as we don't really use fansi in contexts different than debugging and error handling. I'll investigate.

lbialy commented 1 month ago

Ok, so this is a much bigger problem than just fansi having issues with parsing some escape codes. It seems Pulumi engine does something to escape codes and even if I disable trace logging that leads to this exception the besom program does not terminate at all in your sample. I guess something goes horribly wrong on pulumi's side but I'm still researching.

lbialy commented 1 month ago

Ha, problem is on our side (in fansi and our pretty printer). I have a solution that works.

lbialy commented 1 month ago

fixed in #492