[issue21677] Exception context set to string by BufferedWriter.close()

2014-06-10 Thread Antoine Pitrou

Antoine Pitrou added the comment:

This changeset crashes test_io here:

test_close_error_on_close (test.test_io.CBufferedReaderTest) ... python: 
Objects/abstract.c:2091: PyObject_Call: Assertion `(result != ((void *)0)  
!PyErr_Occurred()) || (result == ((void *)0)  PyErr_Occurred())' failed.
Fatal Python error: Aborted

Current thread 0x7ff1b3264740 (most recent call first):
  File /home/antoine/cpython/default/Lib/test/test_io.py, line 793 in 
test_close_error_on_close
  File /home/antoine/cpython/default/Lib/unittest/case.py, line 577 in run
  File /home/antoine/cpython/default/Lib/unittest/case.py, line 625 in 
__call__
  File /home/antoine/cpython/default/Lib/unittest/suite.py, line 125 in run
  File /home/antoine/cpython/default/Lib/unittest/suite.py, line 87 in 
__call__
  File /home/antoine/cpython/default/Lib/unittest/suite.py, line 125 in run
  File /home/antoine/cpython/default/Lib/unittest/suite.py, line 87 in 
__call__
  File /home/antoine/cpython/default/Lib/unittest/suite.py, line 125 in run
  File /home/antoine/cpython/default/Lib/unittest/suite.py, line 87 in 
__call__
  File /home/antoine/cpython/default/Lib/unittest/runner.py, line 168 in run
  File /home/antoine/cpython/default/Lib/test/support/__init__.py, line 1724 
in _run_suite
  File /home/antoine/cpython/default/Lib/test/support/__init__.py, line 1758 
in run_unittest
  File /home/antoine/cpython/default/Lib/test/regrtest.py, line 1277 in 
lambda
  File /home/antoine/cpython/default/Lib/test/regrtest.py, line 1278 in 
runtest_inner
  File /home/antoine/cpython/default/Lib/test/regrtest.py, line 978 in runtest
  File /home/antoine/cpython/default/Lib/test/regrtest.py, line 763 in main
  File /home/antoine/cpython/default/Lib/test/regrtest.py, line 1562 in 
main_in_temp_cwd
  File /home/antoine/cpython/default/Lib/test/__main__.py, line 3 in module
  File /home/antoine/cpython/default/Lib/runpy.py, line 85 in _run_code
  File /home/antoine/cpython/default/Lib/runpy.py, line 170 in 
_run_module_as_main
Abandon

--
nosy: +ned.deily
status: closed - open

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21677
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21677] Exception context set to string by BufferedWriter.close()

2014-06-10 Thread Antoine Pitrou

Antoine Pitrou added the comment:

gdb backtrace:

#0  0x7711ff79 in __GI_raise (sig=sig@entry=6) at 
../nptl/sysdeps/unix/sysv/linux/raise.c:56
#1  0x77123388 in __GI_abort () at abort.c:89
#2  0x77118e36 in __assert_fail_base (fmt=0x7726a718 %s%s%s:%u: 
%s%sAssertion `%s' failed.\n%n, 
assertion=assertion@entry=0x670d48 (result != ((void *)0)  
!PyErr_Occurred()) || (result == ((void *)0)  PyErr_Occurred()), 
file=file@entry=0x670332 Objects/abstract.c, line=line@entry=2077, 
function=function@entry=0x670ff6 __PRETTY_FUNCTION__.10598 
PyObject_Call) at assert.c:92
#3  0x77118ee2 in __GI___assert_fail (
assertion=0x670d48 (result != ((void *)0)  !PyErr_Occurred()) || (result 
== ((void *)0)  PyErr_Occurred()), 
file=0x670332 Objects/abstract.c, line=2077, function=0x670ff6 
__PRETTY_FUNCTION__.10598 PyObject_Call) at assert.c:101
#4  0x00461e89 in PyObject_Call (func=0x727013d8, 
arg=0x76638ef8, kw=0x0) at Objects/abstract.c:2076
#5  0x00462f62 in PyObject_CallFunctionObjArgs 
(callable=0x727013d8) at Objects/abstract.c:2362
#6  0x00463c46 in PyObject_IsSubclass (derived=0x911140 
_PyExc_OSError, cls=0x911140 _PyExc_OSError)
at Objects/abstract.c:2617
#7  0x005cc591 in PyErr_NormalizeException (exc=0x7ffdc578, 
val=0x7ffdc580, tb=0x7ffdc588)
at Python/errors.c:254
#8  0x00639bc6 in buffered_close (self=0x77e6ad78, args=0x0) at 
./Modules/_io/bufferedio.c:552


It seems PyErr_NormalizeException doesn't like being called with an exception 
set.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21677
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21677] Exception context set to string by BufferedWriter.close()

2014-06-10 Thread Roundup Robot

Roundup Robot added the comment:

New changeset a98fd4eeed40 by Serhiy Storchaka in branch '3.4':
PyErr_NormalizeException doesn't like being called with an exception set
http://hg.python.org/cpython/rev/a98fd4eeed40

New changeset 55c50c570098 by Serhiy Storchaka in branch 'default':
PyErr_NormalizeException doesn't like being called with an exception set
http://hg.python.org/cpython/rev/55c50c570098

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21677
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21677] Exception context set to string by BufferedWriter.close()

2014-06-10 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Thank you Antoine. Perhaps this non-trivial code for chaining exceptions 
(repeated at least three times) should be extracted to separate function.

--
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21677
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21677] Exception context set to string by BufferedWriter.close()

2014-06-09 Thread Roundup Robot

Roundup Robot added the comment:

New changeset a3b7b89da34f by Serhiy Storchaka in branch '3.4':
Issue #21677: Fixed chaining nonnormalized exceptions in io close() methods.
http://hg.python.org/cpython/rev/a3b7b89da34f

New changeset d6ac4b6020b9 by Serhiy Storchaka in branch 'default':
Issue #21677: Fixed chaining nonnormalized exceptions in io close() methods.
http://hg.python.org/cpython/rev/d6ac4b6020b9

--
nosy: +python-dev

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21677
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21677] Exception context set to string by BufferedWriter.close()

2014-06-09 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Thank you Martin for your report.

--
resolution:  - fixed
stage: patch review - resolved
status: open - closed
versions:  -Python 2.7

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21677
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21677] Exception context set to string by BufferedWriter.close()

2014-06-07 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Here is a patch. It fixes also the same error in TextIOWrapper.

--
assignee:  - serhiy.storchaka
keywords: +patch
stage:  - patch review
versions: +Python 2.7, Python 3.5
Added file: 
http://bugs.python.org/file35509/io_nonnormalized_error_on_close.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21677
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21677] Exception context set to string by BufferedWriter.close()

2014-06-06 Thread Martin Panter

New submission from Martin Panter:

I made a writer class whose write() and flush() methods (unintentionally) 
triggered exceptions. I wrapped this in a BufferedWriter. When close() is 
called, the resulting exception has a string object in its __context__ 
attribute. Although the original error was my fault, it created a confusing 
chain reaction of exception reports.

 from io import BufferedWriter, RawIOBase
 import sys
 
 class BuggyWriter(RawIOBase):
... def writable(self): return True
... def write(self, b): in_write  # Initial exception
... def flush(self): raise Exception(In flush())
... 
 output = BufferedWriter(BuggyWriter())
 output.write(bdata)
4
 output.close()  # Note the TypeError printed at the top
TypeError: print_exception(): Exception expected for value, str found

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File stdin, line 1, in module
  File stdin, line 4, in flush
Exception: In flush()
 
 sys.last_value
Exception('In flush()',)
 sys.last_value.__context__  # Should be exception, not string object
name 'in_write' is not defined
 
 import traceback
 traceback.print_exception(sys.last_type, sys.last_value, sys.last_traceback)
Traceback (most recent call last):
  File stdin, line 1, in module
  File /usr/lib/python3.4/traceback.py, line 169, in print_exception
for line in _format_exception_iter(etype, value, tb, limit, chain):
  File /usr/lib/python3.4/traceback.py, line 146, in _format_exception_iter
for value, tb in values:
  File /usr/lib/python3.4/traceback.py, line 138, in _iter_chain
yield from it
  File /usr/lib/python3.4/traceback.py, line 125, in _iter_chain
context = exc.__context__
AttributeError: 'str' object has no attribute '__context__'

--
components: IO
messages: 219864
nosy: vadmium
priority: normal
severity: normal
status: open
title: Exception context set to string by BufferedWriter.close()
type: behavior
versions: Python 3.4

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21677
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21677] Exception context set to string by BufferedWriter.close()

2014-06-06 Thread Serhiy Storchaka

Changes by Serhiy Storchaka storch...@gmail.com:


--
nosy: +benjamin.peterson, pitrou, serhiy.storchaka, stutzbach

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21677
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com