Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print build errors to stderr #4494

Merged
merged 1 commit into from Jul 12, 2017

Conversation

bew
Copy link
Contributor

@bew bew commented May 31, 2017

This addresses #4451

There are some cases which needs discussion about where to prints them:

  • usages messages on missing CLI argument
  • build errors when output format is JSON

@mverzilli
Copy link

LGTM! I think the two cases you mention should also print to stderr. Why would you send them to stdout?

@bew
Copy link
Contributor Author

bew commented Jun 4, 2017

About the JSON formatted errors, I'm thinking about the use-case of using shell commands:

$ crystal build --format json file.cr | use_the_json_output

Once the JSON errors will be on stderr, they'll have a hard time getting the correct stream to go in the pipe to use_the_json_output program.

But maybe it's not our business, and it should stay on stderr, as most users will use their language's stdlib to spawn a process and granuraly get it's stdout/stderr programmatically.

@bew bew force-pushed the build-errors-to-stderr branch 4 times, most recently from c9bc54e to 06a304d Compare June 6, 2017 15:28
@bew
Copy link
Contributor Author

bew commented Jun 6, 2017

I fixed the specs, but now I don't know why the build doesn't work, did I broke something else? https://travis-ci.org/crystal-lang/crystal/jobs/240012478

@Sija
Copy link
Contributor

Sija commented Jun 6, 2017

@bew so far, so (green) good... :)

@RX14
Copy link
Contributor

RX14 commented Jun 6, 2017

The travis build fails so often on osx, why don't we just disable it or ignore the results and use circleci only?

@bew
Copy link
Contributor Author

bew commented Jun 20, 2017

Rebased, osx still failing, are we waiting for #4528 to be merged? Or can we merge this PR soon?

@Sija
Copy link
Contributor

Sija commented Jun 24, 2017

Looks like GTG, merge-time?

@akzhan
Copy link
Contributor

akzhan commented Jul 1, 2017

I'm unsure to write errors to STDERR in JSON output case.

Better to choose output stream by output format. Errors to JSON to STDOUT is ok. Isn't it?

@Sija
Copy link
Contributor

Sija commented Jul 1, 2017

@akzhan I'd expect to see errors on STDERR on non-success process exit...

@bew
Copy link
Contributor Author

bew commented Jul 12, 2017

@akzhan I believe that an error message should always go to stderr, whatever the output format is.

@akzhan
Copy link
Contributor

akzhan commented Jul 12, 2017

@Sija @bew Ok.

@RX14
Copy link
Contributor

RX14 commented Jul 12, 2017

Looks good to me, would be nice if we could spec this behaviour but i'm not really opposed to landing this without specs.

@mverzilli
Copy link

Restarted the build (I know, I know, we'll tackle that soon :)).

@RX14
Copy link
Contributor

RX14 commented Jul 12, 2017

@mverzilli this PR is from may so I guess it doesn't have the .travis.yml merged so that OSX is an allowed failure.

Remove unnecessary I/O flush, it's already done in the `main`.

Note: The notation `command 2>&1 >/dev/null` will close stdout, then
redirect stderr to (a new) stdout.
@bew
Copy link
Contributor Author

bew commented Jul 12, 2017

@RX14 You're right, I've rebased the branch on current master it should be good now.

@bew
Copy link
Contributor Author

bew commented Jul 12, 2017

I've found another place where output should go on STDERR:

diff --git a/src/spec.cr b/src/spec.cr
index 2c3c303a5..aa49cdbcf 100644
--- a/src/spec.cr
+++ b/src/spec.cr
@@ -83,8 +83,8 @@ OptionParser.parse! do |opts|
     if location =~ /\A(.+?)\:(\d+)\Z/
       Spec.add_location $1, $2.to_i
     else
-      puts "location #{location} must be file:line"
-      exit
+      STDERR.puts "location #{location} must be file:line"
+      exit 1
     end
   end
   opts.on("--junit_output OUTPUT_DIR", "generate JUnit XML output") do |output_dir|
@@ -106,7 +106,7 @@ OptionParser.parse! do |opts|
 end

 unless ARGV.empty?
-  puts "Error: unknown argument '#{ARGV.first}'"
+  STDERR.puts "Error: unknown argument '#{ARGV.first}'"
   exit 1
 end

Should I add this change in this PR ? (it's not a build error, but it's still an error)

@Sija
Copy link
Contributor

Sija commented Jul 12, 2017

@bew IMHO it's an addition in line with this PR, so yes, I'd add it too.

@RX14
Copy link
Contributor

RX14 commented Jul 12, 2017

@bew that's not actually build errors though is it? I'm fine with modifying the spec runner in this PR but the commit should be renamed to "Print build and spec errors to stderr".

@bew
Copy link
Contributor Author

bew commented Jul 12, 2017

Indeed it's not a build error, that's why I asked first.

I'll make another PR later today (or someone else can if he wants to!) for the spec runners, as it was not in the scope of this PR to check every possible print/puts.

@RX14
Copy link
Contributor

RX14 commented Jul 12, 2017

@bew so, is this ready to merge?

@bew
Copy link
Contributor Author

bew commented Jul 12, 2017

If you all agree, yes I think so.

@mverzilli mverzilli merged commit ffb748f into crystal-lang:master Jul 12, 2017
@mverzilli
Copy link

Great job @bew! Thank you ❤️

@mverzilli mverzilli added this to the Next milestone Jul 12, 2017
@bew bew deleted the build-errors-to-stderr branch July 12, 2017 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants