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

Cannot catch dylink's RepyImportError #141

Open
choksi81 opened this issue Jun 3, 2014 · 2 comments
Open

Cannot catch dylink's RepyImportError #141

choksi81 opened this issue Jun 3, 2014 · 2 comments

Comments

@choksi81
Copy link
Contributor

choksi81 commented Jun 3, 2014

I'm writing a unit test to verify dylink's requirement to supply library file names including extensions, see #1317. When testing a "bad" case and trying to catch the RepyImportError that is raised, I don't succeed.
If dylink isn't imported in my test script, then RepyImportError is unknown:

try:
  dy_import_module_symbols("nonexistentlibrary")
  # Fails with dy_import_module() too!
except RepyImportError:
  log("Can catch RepyImportError!\n")

# Result:
# Exception (with type 'exceptions.NameError'): name 'RepyImportError' is not defined

Adding an import at the top, no matter if dy_import_module or the ..._symbols one, still doesn't let me catch the error:

Exception (with class '.RepyImportError'): Failed to locate the module! Module: 'nonexistentlibrary' Cannot openfile non-existent file "nonexistentlibrary" without creating it!

Now RepyImportError inherits from Exception (rather than RepyException which I think should rather be used, see the exception hierarchy), but changing to that base class doesn't help either.
Note: This problem looks similar to one with SocketTimeoutError that Monzur ran into and worked around using a blanket except.

@aaaaalbert
Copy link
Contributor

I should add that in order to enable the dy_import_module* calls in a Repy program, you call the interpreter with dylink.r2py as the program to run, and give it your program's name as the first argument. dylink then reads in the code and does the imports.

Running this way should also add the import error to the context of the user program, not only the import functions.

By the way, the problem Monzur saw is different. It'srelated to repyportability's use of dylink, see SeattleTestbed/portability#28.

@aaaaalbert
Copy link
Contributor

To be more conrete, adding RepyImportError to the import_context here fixes the problem.

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

No branches or pull requests

2 participants