Skip to content

pkl format - ParserError on invalid escape sequence instead of actionable error message #1421

@Postremus

Description

@Postremus

I ran format on a file with an invalid escape sequence. This resulted in a stacktrace.
Compare this to pkl eval, where I get a nicer looking error message. Maybe pkl format can show the same / or similar message?

pkl:: Pkl 0.30.2 (Windows 10.0, native)

Module:

x = "/dump/\${SOURCE_DB_NAME}.dump"

pkl format:

C:\workspaces\workspace_wolf\wolf-deployment\src\wolf>pkl format Test.pkl
An unexpected error has occurred. Would you mind filing a bug report?

org.pkl.parser.ParserError: Invalid character escape sequence `\$`.

Valid character escape sequences are:  \n  \r  \t  \"  \\
        at org.pkl.parser.Lexer.lexError(Lexer.java:721)
        at org.pkl.parser.Lexer.lexEscape(Lexer.java:452)
        at org.pkl.parser.Lexer.nextString(Lexer.java:272)
        at org.pkl.parser.Lexer.next(Lexer.java:83)
        at org.pkl.parser.GenericParser.init(GenericParser.java:42)
        at org.pkl.parser.GenericParser.parseModule(GenericParser.java:52)
        at org.pkl.formatter.Formatter.format(Formatter.kt:49)
        at org.pkl.cli.CliFormatterCommand.format(CliFormatterCommand.kt:49)
        at org.pkl.cli.CliFormatterCommand.handlePaths(CliFormatterCommand.kt:111)
        at org.pkl.cli.CliFormatterCommand.doRun(CliFormatterCommand.kt:81)
        at org.pkl.commons.cli.CliCommand.run(CliCommand.kt:47)
        at org.pkl.cli.commands.FormatterCommand.run(FormatterCommand.kt:97)
        at com.github.ajalt.clikt.core.CoreCliktCommandKt.parse(CoreCliktCommand.kt:107)
        at com.github.ajalt.clikt.core.CoreCliktCommandKt.main(CoreCliktCommand.kt:78)
        at com.github.ajalt.clikt.core.CoreCliktCommandKt.main(CoreCliktCommand.kt:90)
        at org.pkl.cli.Main.main$lambda$0(Main.kt:26)
        at org.pkl.commons.cli.CliMainKt.cliMain(CliMain.kt:33)
        at org.pkl.cli.Main.main(Main.kt:26)
        at java.base@25/java.lang.invoke.LambdaForm$DMH/sa346b79c.invokeStaticInit(LambdaForm$DMH)

pkl eval

C:\workspaces\workspace_wolf\wolf-deployment\src\wolf>pkl eval Test.pkl  
ÔÇôÔÇô Pkl Error ÔÇôÔÇô
Invalid character escape sequence `\$`.
                                                                                                                                                                                                                                                                                   
Valid character escape sequences are:  \n  \r  \t  \"  \\                                                                                                                                                                                                                          

1 | x = "/dump/\${SOURCE_DB_NAME}.dump"
               ^^
at Test (file:///C:/workspaces/workspace_wolf/wolf-deployment/src/wolf/Test.pkl, line 1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions