Purescript: Print compilation errors to standard output

Created on 11 Jun 2019  Â·  4Comments  Â·  Source: purescript/purescript

Currently compile errors are printed to stderr. At first this seems correct ("isn't stderr for errors?") but bear with me: stdout is really for (potentially machine-readable) output which we are expecting to see / have asked for, whereas stderr is for diagnostic information to help you realise if/when a program is not running correctly. See this blog post for more details. My argument, in a nutshell, is that compile errors fit better into the first category, and thus they ought to be printed to stdout.

This is particularly noticeable when trying to compile with the --json-errors flag. In practice you will almost always need to do some gymnastics to redirect output streams, such as in this example from one of our Makefiles:

        npm run --silent build:purs:json 2>&1 1>/dev/null | \
        node_modules/purescript-suggest/cli/index.js --apply

If the --json-errors flag is being used it's almost always because we want the output to be piped to another program. Printing errors to stdout would make this easy by default.

Another unfortunate consequence of compile errors getting printed to stderr is that it conflicts with other warnings, such as the glob miss warnings:

$ purs compile asdfasdf >/dev/null
purs compile: No files found using pattern: asdfasdf
purs compile: No input files.
Usage: For basic information, try the `--help' option.

These warnings are correctly printed to stderr, but since --json-errors output is _also_ printed to stderr, we need to suppress them if we're using --json-errors, so that the stderr output can be parsed as json, see #1811. This is an awkward workaround for a problem which wouldn't have arisen in the first place if compile errors were always printed to stdout.

To summarize:

| Output type | Where it goes now | Where it (imo) ought to go |
| -- | -- | -- |
| Compile errors | stderr | stdout ✗ |
| Glob miss warnings | stderr (but only without --json-errors) | stderr ✓ |
| CLI errors (purs --invalid-option) | stderr | stderr ✓ |
| Progress messages ("Compiling Prelude") | stdout | stderr ✗ |

breaking

Most helpful comment

I'd like to do this in v0.14.0

All 4 comments

I suspect the compiler cannot just switch to the correct output destinations as all the tooling (e.g. editor plugins) needs to be adapted first? (and/or coordinate a release)

Yes, we'd need to do this in a breaking release. If we were going to do this I think we should indeed coordinate with tooling maintainers to let them know that they should either drop support for previous versions of the compiler or update their tooling so that it knows which output stream to read from, depending on the compiler version in use.

Big yes from me. From my perspective, there's some junk around from wrappers too with --json-errors, and I'm likely (at least in the short term) to move to just reading the JSON output on either stderr or stdout (and skipping junk) for purescript-suggest and purescript-language-server - so that's a change that can be released prior to the compiler release (though the compiler may be moving considerably faster than I am these days).

I'd like to do this in v0.14.0

Was this page helpful?
0 / 5 - 0 ratings