]> granicus.if.org Git - python/commitdiff
Backport r61468 from trunk: Improves the text of the IOError raised
authorGregory P. Smith <greg@mad-scientist.com>
Sat, 3 May 2008 07:12:23 +0000 (07:12 +0000)
committerGregory P. Smith <greg@mad-scientist.com>
Sat, 3 May 2008 07:12:23 +0000 (07:12 +0000)
when open() returns EINVAL.  See issue2158.

Objects/fileobject.c

index f954e36fa596e1f559ba24229654fbb426dea6d1..565bf5ca2f78c23f3adc256d9cb2f935a47aa941 100644 (file)
@@ -256,9 +256,12 @@ open_the_file(PyFileObject *f, char *name, char *mode)
                else if (errno == EINVAL) /* unknown, but not a mode string */
                        errno = ENOENT;
 #endif
+                /* EINVAL is returned when an invalid filename or
+                 * an invalid mode is supplied. */
                if (errno == EINVAL)
-                       PyErr_Format(PyExc_IOError, "invalid mode: %s",
-                                    mode);
+                       PyErr_Format(PyExc_IOError,
+                                     "invalid filename: %s or mode: %s",
+                                    name, mode);
                else
                        PyErr_SetFromErrnoWithFilenameObject(PyExc_IOError, f->f_name);
                f = NULL;