Skip to content

Commit c1ea281

Browse files
Add standard error to exception message
The rationale is that when castxml has an error it raises a RuntimeError to the user with the message. However, the message only contains the stdout from castxml - this makes the RuntimeError contain no information about what actually went wrong. This change allows the user to add error handling to their applications based on what went wrong with castxml (such as changing their include directories, etc)
1 parent aa5920c commit c1ea281

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

pygccxml/parser/source_reader.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,8 @@ def create_xml_file(self, source_file, destination=None):
231231
process = subprocess.Popen(
232232
args=command_line,
233233
shell=True,
234-
stdout=subprocess.PIPE)
234+
stdout=subprocess.PIPE,
235+
stderr=subprocess.PIPE)
235236

236237
try:
237238
results = []
@@ -242,9 +243,12 @@ def create_xml_file(self, source_file, destination=None):
242243
for line in process.stdout.readlines():
243244
if line.strip():
244245
results.append(line.rstrip())
246+
for line in process.stderr.readlines():
247+
if line.strip():
248+
results.append(line.rstrip())
245249

246250
exit_status = process.returncode
247-
msg = os.linesep.join([str(s) for s in results])
251+
msg = os.linesep.join([str(s.decode()) for s in results])
248252
if self.__config.ignore_gccxml_output:
249253
if not os.path.isfile(xml_file):
250254
raise RuntimeError(

unittests/source_reader_tester.py

+12
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# See http://www.boost.org/LICENSE_1_0.txt
55

66
import unittest
7+
import os
78

89
from . import parser_test_case
910

@@ -31,6 +32,17 @@ def test_compound_argument_type(self):
3132
self.assertTrue(do_smth, "unable to find do_smth")
3233
do_smth.function_type()
3334

35+
def test_stderr_present_and_readable(self):
36+
with open(os.path.join('unittests', 'data', self.header), 'r') as f:
37+
source_str = f.read()
38+
39+
err_str = "add some stuff that should not compile"
40+
source_str += err_str
41+
with self.assertRaises(RuntimeError) as e_context:
42+
decls = parser.parse_string(source_str, self.config)
43+
44+
self.assertIn(err_str, e_context.exception.args[0])
45+
3446

3547
def create_suite():
3648
suite = unittest.TestSuite()

0 commit comments

Comments
 (0)