1 # SPDX-License-Identifier: BSD-2-Clause
3 # Copyright (c) 2016, Matt Layman
8 def format_exception(exception
):
9 """Format an exception as diagnostics output.
11 exception is the tuple as expected from sys.exc_info.
13 exception_lines
= traceback
.format_exception(*exception
)
14 # The lines returned from format_exception do not strictly contain
15 # one line per element in the list (i.e. some elements have new
16 # line characters in the middle). Normalize that oddity.
17 lines
= ''.join(exception_lines
).splitlines(True)
18 return format_as_diagnostics(lines
)
21 def format_as_diagnostics(lines
):
22 """Format the lines as diagnostics output by prepending the diagnostic #.
24 This function makes no assumptions about the line endings.
26 return ''.join(['# ' + line
for line
in lines
])
This page took 0.029684 seconds and 4 git commands to generate.