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

On macro run error: show status, stdout and stderr #4614

Merged
merged 2 commits into from Aug 18, 2017

Conversation

bew
Copy link
Contributor

@bew bew commented Jun 23, 2017

First PR to display more information about a failing macro run.
Another PR might come to display the errors without the backtrace from ecr/processor to properly resolve #4577

Given thoses files:

# processor.cr

def func
  raise "Some exception happened" # This will always fail
end

puts %(puts "some stuff on stdout")

begin
  func
rescue e
  STDERR.puts "ERROR: #{e}"
  exit 1
end
# test_run.cr

{{ run "./processor" }}

Compilation will give:

$ crystal ./test_run.cr
Error in test_run.cr:1: expanding macro

{{ run "./processor" }}
^

in test_run.cr:1: Error executing run (exit code: 1): ./processor 

---- Got on stdout: ----

puts "some stuff on stdout"


---- Got on stderr: ----

ERROR: Some exception happened



{{ run "./processor" }}
   ^~~

If you have any other ideas how to present stdout & stderr, I'm open to suggestion.

There is currently no specs on the macro method run, should I try to make one for this?

@bew bew force-pushed the show-errors-for-macro-run branch from b21d840 to 79b06e3 Compare June 27, 2017 16:04
@RX14
Copy link
Contributor

RX14 commented Jul 6, 2017

Somehow I don't like the "---- Got on stdout: ----" lines, they seem to have a different look and feel to the rest of the compiler error output. I get that that's a wishy-washy complaint but it feels wrong.

@bew
Copy link
Contributor Author

bew commented Jul 6, 2017

@RX14 I agree completely, but I don't have any idea how this could be presented.
If you have one, I'll be happy to do it.

@straight-shoota
Copy link
Member

Maybe indent the stream output?

in test_run.cr:1: Error executing run (exit code: 1): ./processor 

    puts "some stuff on stdout"

stderr:

    ERROR: Some exception happened

    {{ run "./processor" }}
       ^~~

Copy link
Contributor

@ysbaddaden ysbaddaden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe indent. Otherwise 👌

@bew
Copy link
Contributor Author

bew commented Jul 7, 2017

Thanks a lot for your approvals ;)
@straight-shoota I'll do the indent, it's wayy nicer, thanks!

@bew bew force-pushed the show-errors-for-macro-run branch 2 times, most recently from 01beb9b to 70b21d2 Compare July 7, 2017 08:55
@bew
Copy link
Contributor Author

bew commented Jul 7, 2017

Following @straight-shoota suggestion, it now looks like:

Error in test_run.cr:1: expanding macro

{{ run "./processor" }}
^

in test_run.cr:1: Error executing run (exit code: 1): ./processor 

stdout:

    puts "some stuff on stdout"

stderr:

    ERROR: Some exception happened


{{ run "./processor" }}
   ^~~

@bew
Copy link
Contributor Author

bew commented Jul 7, 2017

Also, the error message is in bold, do I try to remove it for stdout and stderr?
macro_run_errors

@RX14
Copy link
Contributor

RX14 commented Jul 7, 2017

@bew stdout: and stderr: should be bold but the output shouldn't be.

@bew
Copy link
Contributor Author

bew commented Jul 7, 2017

stdout: and stderr: should be bold but the output shouldn't be.

@RX14 How should I go about this? I couldn't get colorize to work to remove any coloring/format for a specific text.

@RX14
Copy link
Contributor

RX14 commented Aug 17, 2017

@bew In this case you'll probably have to manually insert the "reset" escape code ("\e[0") to reset the formatting, then use colorize after that.

@bew bew force-pushed the show-errors-for-macro-run branch from 70b21d2 to 13a94f5 Compare August 17, 2017 09:57
@bew
Copy link
Contributor Author

bew commented Aug 17, 2017

Rebased. Thanks @RX14 for the tip. Even if I don't like hardcoding the terminal escape code, and kind of bypassing the Colorize module, it has the merit to work!

macro_run_errors

if result.stdout.empty? && result.stderr.empty?
message << "\nGot no output."
else
message << "\e[0m" if Colorize.enabled?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a Colorize#reset method would be interesting?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would do it, yes, should I open another PR for this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind squashing your commits then add another one that implements Colorize#reset?

Copy link
Contributor Author

@bew bew Aug 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ysbaddaden how would it be used?

message << Colorize.reset
message << "".colorize.reset
# --> does it make sense to have: "abc".colorize.reset   ?
Colorize.reset(message)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I believe "abc".colorize.reset makes sense: we want to print a string and make sure the ASCII escape codes have been reset.

Thought this is about disabling escape codes, it's still adding escape codes to the string, so we should follow the actual API (as .bold, ...)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for "abc".colorize.reset, should I save the current formatting, reset, put "abc", then restore the formatting? Or should I go simple for this PR, and just reset and put the text?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually think that Colorize.reset is a better API. Using String#colorize implies you want to do something to a string, and most importantly that whatever changes you made will be reset afterwards. With String#colorize.reset you don't get that, there's no way to restore the old colours at the end of the string, so I don't think that API makes sense.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@bew bew force-pushed the show-errors-for-macro-run branch from 13a94f5 to 500e9fc Compare August 18, 2017 13:53
@bew
Copy link
Contributor Author

bew commented Aug 18, 2017

So I rebased, squashed, and added Colorize.reset(io).
Good to go? 👍

@RX14
Copy link
Contributor

RX14 commented Aug 18, 2017

Perhaps the Colorize.reset commit should come before the other one so it can use it directly?

@bew bew force-pushed the show-errors-for-macro-run branch from 500e9fc to a7776b9 Compare August 18, 2017 14:10
@bew
Copy link
Contributor Author

bew commented Aug 18, 2017

@RX14 done.

@RX14 RX14 merged commit 5accf4e into crystal-lang:master Aug 18, 2017
@RX14 RX14 added this to the Next milestone Aug 18, 2017
@bew bew deleted the show-errors-for-macro-run branch August 18, 2017 18:12
Copy link
Contributor Author

@bew bew left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just discovered I missed something, what do I do? new PR with the fix?

message.puts
result.stderr.each_line do |line|
message << " "
message << line
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed the \n

message.puts
result.stdout.each_line do |line|
message << " "
message << line
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed the \n

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.

ECR.embed with missing file gives an unclear error message
5 participants