Menu

Error handling bug in evalFile?

Help
someone972
2015-05-27
2015-05-29
  • someone972

    someone972 - 2015-05-27

    I believe there may be a bug in how error handling is done for evalFile. Introducing a blatant python parsing error and calling evalFile, then calling PythonQt::self()->hadError() does not indicate that an error occurred. The error is written to stderr, however. I have isolated why this occurs to the evalFile function. The error is properly set in parseFile. Since handleError calls Py_ErrClear, when the error is cleared and handleError called again in evalFile, the error is no longer indicated. Removing the clearError and handleError calls from evalFile made it so it properly detects the error. Is this the proper way to fix it so evalFile properly sets the error flag?

    For reference, here's the code for evalFile and parseFile.

    void PythonQt::evalFile(PyObject* module, const QString& filename)
    {
      PythonQtObjectPtr code = parseFile(filename);
      clearError(); //This clears previously set error!
      if (code) {
        evalCode(module, code);
      } else {
        handleError(); //This will no longer indicate an error since PyErr_Clear was called.
      }
    }
    
    PythonQtObjectPtr PythonQt::parseFile(const QString& filename)
    {
      PythonQtObjectPtr p;
      p.setNewRef(PythonQtImport::getCodeFromPyc(filename));
      clearError();
      if (!p) {
        handleError();
      }
      return p;
    }
    
     
  • Florian Link

    Florian Link - 2015-05-28

    Thanks for reporting, I will fix this.

     
  • Florian Link

    Florian Link - 2015-05-29

    This has been fixed on the svn trunk.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.