Skip to content

Commit bb38b42

Browse files
committed
Fix exception causes in code.py
1 parent 9df73e6 commit bb38b42

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

sphinx/directives/code.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,12 @@ def read_file(self, filename: str, location: Tuple[str, int] = None) -> List[str
227227
text = text.expandtabs(self.options['tab-width'])
228228

229229
return text.splitlines(True)
230-
except OSError:
231-
raise OSError(__('Include file %r not found or reading it failed') % filename)
232-
except UnicodeError:
230+
except OSError as e:
231+
raise OSError(__('Include file %r not found or reading it failed') % filename) from e
232+
except UnicodeError as e:
233233
raise UnicodeError(__('Encoding %r used for reading included file %r seems to '
234234
'be wrong, try giving an :encoding: option') %
235-
(self.encoding, filename))
235+
(self.encoding, filename)) from e
236236

237237
def read(self, location: Tuple[str, int] = None) -> Tuple[str, int]:
238238
if 'diff' in self.options:

0 commit comments

Comments
 (0)