diff --git a/Misc/NEWS.d/next/Windows/2020-06-12-15-29-18.bpo-27729.nNXQot.rst b/Misc/NEWS.d/next/Windows/2020-06-12-15-29-18.bpo-27729.nNXQot.rst new file mode 100644 index 00000000000..695200ef7cc --- /dev/null +++ b/Misc/NEWS.d/next/Windows/2020-06-12-15-29-18.bpo-27729.nNXQot.rst @@ -0,0 +1 @@ +Give a better error message when a file path is too long on Windows. diff --git a/Python/errors.c b/Python/errors.c index 5d1725679c4..31de0dbce1e 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -700,7 +700,11 @@ PyErr_SetFromErrnoWithFilenameObjects(PyObject *exc, PyObject *filenameObject, P table, we use it, otherwise we assume it really _is_ a Win32 error code */ - if (i > 0 && i < _sys_nerr) { + if (i == ENOENT && GetLastError() == ERROR_PATH_NOT_FOUND) { + message = PyUnicode_FromString("No such path or path exceeds " + "maximum allowed length"); + } + else if (i > 0 && i < _sys_nerr) { message = PyUnicode_FromString(_sys_errlist[i]); } else {