Search code examples
sublimetextbuild-system

How to configure sublime's build system to capture file and line from such error output?


If I don't understand wrong, sublime can capture file and line number from error output, by configure the file_regex or line_regex.

I have such error output:

  main.<anonymous closure>.<anonymous closure>   file:///Users/freewind/dev/workspace/RythmDart/test/test_grammar.dart 135:19

How to configure the build file?

I tried:

"line_regex": "([\\w/:\\-_]*) (\\d*):(\\d*)",

But it doesn't work.


Solution

  • This works for me:

        "file_regex": ".*file:\/\/\/(.*):([0-9]*):[0-9]*",
    

    Note that:

    • this uses a file_regex instead of line_regex
    • I am using Sublime Text 2
    • I am running dart.exe on Windows

    I am running a simple dart command line program and get output like this:

    Hello world
    
    Unhandled exception:
    exception
    #0      main (file:///C:/src_test/dart/dart_test.dart:4:3)
    

    Here is my test program:

    void main() {
      print("Hello world\n");
      throw 'exception';
    }
    

    edit:

    for mac, it should be:

    "file_regex": ".*file:\/\/(.*):([0-9]*):[0-9]*",
    

    Notice there are only two \/s after file:, or sublime will try to find a file with wrong path, e.g.

    ~/dev/dart/myproject/Users/home/freewind/dev/dart/myproject/test.dart

    If I use two \/, it will be correct:

    /Users/home/freewind/dev/dart/myproject/test.dart