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

Add --verbose option and hide internal part of errors by default #18

Closed
stuaxo opened this issue Jan 4, 2013 · 6 comments
Closed

Add --verbose option and hide internal part of errors by default #18

stuaxo opened this issue Jan 4, 2013 · 6 comments

Comments

@stuaxo
Copy link
Contributor

stuaxo commented Jan 4, 2013

if I make an erronious script like

rect(40, 40, 40)

I get an error that includes info internal to shoebot ... by default the user should just get the script error, unless they specify verbose on the commandline:

Example current output

Traceback (most recent call last):
  File "/home/stu/.virtualenvs/shoebot/bin/sbot", line 146, in <module>
    args = args.args)
  File "/home/stu/.virtualenvs/shoebot/local/lib/python2.7/site-packages/shoebot/sbot.py", line 86, in run
    bot.sb_run(src, iterations, run_forever = window if close_window == False else False, frame_limiter = window)
  File "/home/stu/.virtualenvs/shoebot/local/lib/python2.7/site-packages/shoebot/grammar/grammar.py", line 146, in sb_run
    self._exec_frame(source_or_code, limit = frame_limiter)
  File "/home/stu/.virtualenvs/shoebot/local/lib/python2.7/site-packages/shoebot/grammar/grammar.py", line 98, in _exec_frame
    exec source_or_code in namespace
  File "shoebot_code", line 1, in <module>
TypeError: rect() takes at least 5 arguments (4 given)

Desired output (without --verbose) might look something like this..

Traceback (most recent call last):
  File "shoebot_code", line 1, in <module>
TypeError: rect() takes at least 5 arguments (4 given)
@rlafuente
Copy link
Contributor

I started a new branch to deal with this, and done an initial commit (94fb8ef) that trims down the full traceback into a simple error message, along with the offending line. Example:

Error in the Shoebot script, line 1:
    rect(40,40,40)
TypeError: rect() takes at least 5 arguments (4 given)

There's still a bit of work needed:

  • The error in this test script mentions 5 arguments when in fact rect() takes 4, since rect() is actually a Bot method that takes Bot as the first argument. So I'm thinking that a regex replacement would be good here, subtracting 1 in the error message numbers in the relevant cases in order to present to the user the correct argument number.
  • Verbose mode would show the full traceback. I need help here, since the code pipeline changed quite a bit and I haven't yet sat down to fully grok the new Bot/Grammar model in order to add new parameters.
  • This branch needs more testing, especially with the Gedit plugins. The print statements might be problematic -- how can we pipe the output to stdout for CLI scripts, and to the Gedit output buffer for scripts run from Gedit?

@rlafuente
Copy link
Contributor

One last thing about testing -- we need to be sure that complex errors do not get masked by the simplified traceback.

@stuaxo
Copy link
Contributor Author

stuaxo commented Jan 7, 2013

This is a good point about testing.

I think Gedit will be OK, certainly for Gedit3 it'll just be using subprocess running sbot. For Gedit2 I'm fairly sure it's possible to redirect stderr (using the same method as the IDE did).

We'll need to be careful using a regex replacement

  • ideally it will only apply to the calls from the script into the bot grammar (functions in classes that extend grammar.Grammar - this will cover nodebot.Nodebot and drawbot.Drawbot and any future grammars).

We need to not munge output if the user overrides one of our methods...

I guess it might be possible to walk the trace stack to check they are the correct calls somehow ?

@stuaxo
Copy link
Contributor Author

stuaxo commented Jan 18, 2013

Verbose mode would show the full traceback. I need help here, since the code pipeline changed quite a bit and I
haven't yet sat down to fully grok the new Bot/Grammar model in order to add new parameters.

To add a param you'd add it to init_bot inside shoebot/sbot.py this convenience function then pass it to the bot constructor (DrawBot or NodeBot) - then it'd probably be store it inside the Grammar class.

Bot is for stuff that is common to the NodeBot/DrawBot grammars (probably a lot more could be moved here, though I'm not sure this yet, as I'd like to consider supporting say the NodeBoxGL grammar which is kind of different).

Grammar is a lot more basic and has the mecanics to run stuff, but doesn't specify how.

Having a look at the updated gist on how shoebot works as a module https://gist.github.com/1322704 is a good place to see init_bot without loads of parameters.

This branch needs more testing, especially with the Gedit plugins. The print statements might be problematic -- how > can we pipe the output to stdout for CLI scripts, and to the Gedit output buffer for scripts run from Gedit?

The code for this hasn't fully settled down, but it can definitely be made to work (it works most of the time in gedit3, but I'm not fully happy - I still crash it regularly - however as proof of concept it's fine.).

@stuaxo
Copy link
Contributor Author

stuaxo commented Jan 19, 2013

I've added the verbose parameter to sb_run - though non functional, I'm not sure what to change in the traceback code, so back to you :)

@stuaxo
Copy link
Contributor Author

stuaxo commented Feb 5, 2015

About 2 years too late have integrated the change from this branch.

@stuaxo stuaxo closed this as completed Feb 5, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants