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

Feat: output STDERR from the building process #540

Merged
merged 6 commits into from
Jan 18, 2022

Conversation

beta-ziliani
Copy link
Member

Solves #535 by outputting the STDERR of the crystal build to the STDERR of the shards process only if the build is successful. This allows to notice deprecation warnings and the like.

In order to test it, I had to concatenate the STDOUT and STDERR, which isn't as clean as possible but works.

spec/support/factories.cr Outdated Show resolved Hide resolved
src/commands/build.cr Outdated Show resolved Hide resolved
src/commands/build.cr Outdated Show resolved Hide resolved
@luislavena
Copy link
Contributor

luislavena commented Jan 11, 2022

Hello @beta-ziliani, was wondering why not simply inherit error too? That way, you only need to check for success of process status and raise the single error (shown at the bottom) after all the error has been automatically output to you, no need to check if there were errors collected (IO::Memory) and then send that to STDERR later.

I think would be simpler code, but maybe I'm missing what you're trying to achieve as DX.

Cheers.

@straight-shoota
Copy link
Member

Currently, in case of failure the captured STDERR is part of the error message.
If we just pass STDERR through, the output from crystal build would be printed independent of the error and not be part of the error message.
I think it's better to keep it as part of the error message for consistency. That requires capturing and reprinting, but it's not a big deal.

@luislavena
Copy link
Contributor

So in the case of warning:

❯ shards build
Dependencies are satisfied
Building: d
In d.cr:9:1

 9 | a
     ^
Warning: Deprecated top-level a.

A total of 1 warnings were found.

In the case of errors:

❯ shards build
Dependencies are satisfied
Building: d
Error target d failed to compile:
Showing last frame. Use --error-trace for full trace.

In d.cr:3:3

 3 | foo
     ^--
Error: undefined local variable or method 'foo' for top-level

Thought since error is being displayed multiple times, the message about the failed target got lost in the middle, instead of something like:

❯ shards build
Dependencies are satisfied
Building: d
Showing last frame. Use --error-trace for full trace.

In d.cr:3:3

 3 | foo
     ^--
Error: undefined local variable or method 'foo' for top-level
Target d failed to compile

But what you propose makes sense, to make a section in the output with the error. 👍🏽

Cheers.

@straight-shoota
Copy link
Member

We could certainly change the order in the error message! That's not the point.

I'm concerned about maintaining that the message of the exception contains all the error information.

@luislavena
Copy link
Contributor

I'm concerned about maintaining that the message of the exception contains all the error information.

Not sure I follow your concern on that, from what I understand is that Crystal outputs the error message entirely to STDERR, so the error is captured with the current approach.

$ crystal build d.cr --error-trace 
In d.cr:9:1

 9 | a
     ^
Warning: Deprecated top-level a.

A total of 1 warnings were found.

$ crystal build d.cr --error-trace 2>/dev/null

$ echo $?
0

Same for errors:

$ crystal build d.cr --error-trace 
In d.cr:10:1

 10 | foo
      ^--
Error: undefined local variable or method 'foo' for top-level

$ crystal build d.cr --error-trace 2>/dev/null

$ echo $?
1

Thank you.

@straight-shoota
Copy link
Member

@luislavena I meant that the error output from crystal build is contained in the Error exception.

Co-authored-by: Johannes Müller <straightshoota@gmail.com>
@beta-ziliani beta-ziliani merged commit 603badd into crystal-lang:master Jan 18, 2022
@beta-ziliani beta-ziliani deleted the feature/warnings branch January 18, 2022 17:18
@straight-shoota straight-shoota added this to the v0.17.0 milestone Mar 8, 2022
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

3 participants