mirror of
https://github.com/python/cpython.git
synced 2025-09-29 03:35:31 +00:00
bpo-12382: Make OpenDatabase() raise better exception messages (GH-4528)
Previously, 'msilib.OpenDatabase()' function raised a
cryptical exception message when it couldn't open or
create an MSI file. For example:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
_msi.MSIError: unknown error 6e
(cherry picked from commit 4864a619dc
)
This commit is contained in:
parent
90abbee7aa
commit
bfa89b21e1
3 changed files with 20 additions and 0 deletions
|
@ -1,4 +1,5 @@
|
||||||
""" Test suite for the code in msilib """
|
""" Test suite for the code in msilib """
|
||||||
|
import os.path
|
||||||
import unittest
|
import unittest
|
||||||
from test.support import TESTFN, import_module, unlink
|
from test.support import TESTFN, import_module, unlink
|
||||||
msilib = import_module('msilib')
|
msilib = import_module('msilib')
|
||||||
|
@ -40,6 +41,17 @@ class MsiDatabaseTestCase(unittest.TestCase):
|
||||||
)
|
)
|
||||||
self.addCleanup(unlink, db_path)
|
self.addCleanup(unlink, db_path)
|
||||||
|
|
||||||
|
def test_database_open_failed(self):
|
||||||
|
with self.assertRaises(msilib.MSIError) as cm:
|
||||||
|
msilib.OpenDatabase('non-existent.msi', msilib.MSIDBOPEN_READONLY)
|
||||||
|
self.assertEqual(str(cm.exception), 'open failed')
|
||||||
|
|
||||||
|
def test_database_create_failed(self):
|
||||||
|
db_path = os.path.join(TESTFN, 'test.msi')
|
||||||
|
with self.assertRaises(msilib.MSIError) as cm:
|
||||||
|
msilib.OpenDatabase(db_path, msilib.MSIDBOPEN_CREATE)
|
||||||
|
self.assertEqual(str(cm.exception), 'create failed')
|
||||||
|
|
||||||
|
|
||||||
class Test_make_id(unittest.TestCase):
|
class Test_make_id(unittest.TestCase):
|
||||||
#http://msdn.microsoft.com/en-us/library/aa369212(v=vs.85).aspx
|
#http://msdn.microsoft.com/en-us/library/aa369212(v=vs.85).aspx
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
:func:`msilib.OpenDatabase` now raises a better exception message when it
|
||||||
|
couldn't open or create an MSI file. Initial patch by William Tisäter.
|
|
@ -325,6 +325,12 @@ msierror(int status)
|
||||||
case ERROR_INVALID_PARAMETER:
|
case ERROR_INVALID_PARAMETER:
|
||||||
PyErr_SetString(MSIError, "invalid parameter");
|
PyErr_SetString(MSIError, "invalid parameter");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
case ERROR_OPEN_FAILED:
|
||||||
|
PyErr_SetString(MSIError, "open failed");
|
||||||
|
return NULL;
|
||||||
|
case ERROR_CREATE_FAILED:
|
||||||
|
PyErr_SetString(MSIError, "create failed");
|
||||||
|
return NULL;
|
||||||
default:
|
default:
|
||||||
PyErr_Format(MSIError, "unknown error %x", status);
|
PyErr_Format(MSIError, "unknown error %x", status);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue