KEMBAR78
Bad error messages for unterminated strings · Issue #3394 · jashkenas/coffeescript · GitHub
Skip to content

Bad error messages for unterminated strings #3394

@lydell

Description

@lydell

The error messages for unterminated strings are inconsistent, oddly formulated and sometimes point to the wrong point in the code. They are also untested, which led to #3379. I tried and failed to fix this myself in #3392.

  • A ' is not unexpected in these cases:

    $ coffee -pe "'"
    [stdin]:1:1: error: unexpected '
    '
    ^
    
    $ coffee -pe "console.log 'foo"
    [stdin]:1:13: error: unexpected '
    console.log 'foo
                ^
    
    $ coffee -ps
    console.log 'foo
    console.log "bar"
    [stdin]:1:13: error: unexpected '
    console.log 'foo
                ^
    
  • What does “, starting” mean?

    $ coffee -pe '"'
    [stdin]:1:1: error: missing ", starting
    "
    ^
    
    $ coffee -pe 'console.log "foo'
    [stdin]:1:13: error: missing ", starting
    console.log "foo
                ^
    
    $ coffee -ps
    console.log "foo
    console.log 'bar'  
    [stdin]:1:13: error: missing ", starting
    console.log "foo
                ^
    
  • These cases might seem unrelated to unterminated strings, but in a way they are. They were caused by the programmer forgetting to close the “foo” string of the first line. It also seems easy to mess this up; See Improve error messages for unterminated strings #3392. Also, the case with double quotes is wrong.

    $ coffee -ps
    console.log 'foo
    console.log 'bar'
    [stdin]:2:14: error: unexpected bar
    console.log 'bar'
                ^^^
    
    $ coffee -ps
    console.log "foo
    console.log "bar"
    [stdin]:2:17: error: missing ", starting
    console.log "bar"
                    ^
    
  • In interpolations, all errors point to the same place. The pointer should be at either the opening or closing delimiter. Also notice that suddenly ' strings are expected, and the weird “missing X, starting” type of message is used instead.

    $ coffee -ps
    "#{'}"
    [stdin]:1:1: error: missing ', starting
    "#{'}"
    ^
    
    $ coffee -ps
    "#{"}"
    [stdin]:1:1: error: missing }, starting
    "#{"}"
    ^
    
    $ coffee -ps
    "#{foo '}"
    [stdin]:1:1: error: missing ', starting
    "#{foo '}"
    ^
    
    $ coffee -ps
    "#{foo "}"
    [stdin]:1:1: error: missing }, starting
    "#{foo "}"
    ^
    

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions