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

Misleading UnboundLocalError exception #157

Open
Aratz opened this issue Nov 1, 2016 · 0 comments
Open

Misleading UnboundLocalError exception #157

Aratz opened this issue Nov 1, 2016 · 0 comments

Comments

@Aratz
Copy link
Contributor

Aratz commented Nov 1, 2016

In pyurdme.py (dev branch) from line 2289:

            try:
                if self.report_level >= 1:  #stderr & stdout to the terminal
                    handle = subprocess.Popen(urdme_solver_cmd)
                else:
                    handle = subprocess.Popen(urdme_solver_cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
                    stdout, stderr = handle.communicate()
                return_code = handle.wait()
            except OSError as e:
                print "Error, execution of solver raised an exception: {0}".format(e)
                print "urdme_solver_cmd = {0}".format(urdme_solver_cmd) #<-- This message should be forwarded as an exception

            if return_code != 0:
                if self.report_level >= 1:
                    try:
                        print stderr, stdout
                    except Exception as e:
                        pass
                print "urdme_solver_cmd = {0}".format(urdme_solver_cmd)
                raise URDMEError("Solver execution failed, return code = {0}".format(return_code))

If an exception is raised by the solver, "return_code" is never initialized which leads to an UnboundLocalError exception (which is misleading since the problem comes from the solver). OSError should be forwarded instead.

Aratz added a commit to Aratz/pyurdme that referenced this issue Nov 2, 2016
Avoid UnboundLocalError in case solver execution throws an exception.
Information about the solver error is now passed within the
exception message.

fix ahellander#157
Aratz added a commit to Aratz/pyurdme that referenced this issue Nov 2, 2016
Avoid UnboundLocalError in case solver execution throws an exception.
Information about the solver error is now passed within the
exception message.

fix ahellander#157
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

1 participant