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

Added parameter '--throw-exception', which can not be specified togheter... #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mgor
Copy link
Contributor

@mgor mgor commented Apr 13, 2015

Consider the following DNA file:

$ cat test.dna 
.Hello @{name}!

It contains a reference to an undefined python variable called name. When generating the output, there's nothing:

$ ./ribosome.py test.dna 
$ echo $?
0

When adding --rna and executing the resulting code it's quite clear the problem is a variable that isn't defined:

$ ./ribosome.py --rna test.dna | python 
Traceback (most recent call last):
  File "<stdin>", line 259, in <module>
  File "<stdin>", line 213, in dot
  File "<stdin>", line 197, in add
  File "<string>", line 1, in <module>
NameError: name 'name' is not defined

To fix this, and not break backwards compatibility I added a new parameter --throw-exception (couldn't come up with a better name...) which basically works as --rna but writing the RNA code to stdout instead. When specifying the new parameter, the try-catch-exception code parts will not be added to the generated RNA code. The parameter can not be specified at the same time as --rna (mutually exclusive):

$ ./ribosome.py --throw-exception --rna test.dna 
usage: ribosome.py [-h] [-v] [--rna | --throw-exception] dna
ribosome.py: error: argument --rna: not allowed with argument --throw-exception

The new parameter, in combination with using subprocess.Popen() instead of subprocess.call() makes it possible to read stderr for any error messages and display them:

$ ./ribosome.py --throw-exception test.dna 
Traceback (most recent call last):
  File "test.rna", line 259, in <module>
    Block.dot('Hello @{name}!', locals())
  File "test.rna", line 213, in dot
    Block.add(line, bind)
  File "test.rna", line 197, in add
    val = eval(expr, bind)
  File "<string>", line 1, in <module>
NameError: name 'name' is not defined
$ echo $?
1

All "legacy" tests passed!

…ter with '--rna', that will remove the

catch-exception code added the epilogue code if '--rna' isn't specified.

This feature, in combination with using Popen() instead of call(), will make it possible to catch errors in the RNA code,
when not specifying '--rna', which otherwise would go unnoticed.
@eeyrw
Copy link

eeyrw commented Jan 6, 2016

I do need such kind of feature. The ribosome do not output any error information when the py has problem. It's quite hard to trace the problem. I just generate rna file then run in separate for error information.

eeyrw added a commit to eeyrw/ribosome that referenced this pull request Jan 6, 2016
sustrik#31
Make a few modification to run with python3
@mgor
Copy link
Contributor Author

mgor commented Jan 6, 2016

In my use case, I had around 20 dna files representing a section in a big configuration file. The configuration is built using make,

@mgor
Copy link
Contributor Author

mgor commented Jan 6, 2016

Dammit, my son manage to send before I could finish.

...make. Without this fix there wouldn't be any indication on why make couldn't build the file. It would just silently die.

@sustrik
Copy link
Owner

sustrik commented Jan 6, 2016

Uh. Sorry for the delay. I see that GitHub reports merge conflicts for this patch. Would you give it a look?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants