From 6debb0ae1a23a150517e1a034bac641566c71259 Mon Sep 17 00:00:00 2001 From: Min RK Date: Wed, 28 Feb 2018 16:12:43 +0100 Subject: [PATCH] log OSErrors failing to create less-critical files during startup rather than fatal errors --- notebook/notebookapp.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/notebook/notebookapp.py b/notebook/notebookapp.py index 9cd325a1f..d9a1fd4fe 100755 --- a/notebook/notebookapp.py +++ b/notebook/notebookapp.py @@ -711,13 +711,15 @@ class NotebookApp(JupyterApp): h.update(self.password.encode()) return h.digest() - - def _write_cookie_secret_file(self, secret): """write my secret to my secret_file""" self.log.info(_("Writing notebook server cookie secret to %s"), self.cookie_secret_file) - with io.open(self.cookie_secret_file, 'wb') as f: - f.write(secret) + try: + with io.open(self.cookie_secret_file, 'wb') as f: + f.write(secret) + except OSError as e: + self.log.error(_("Failed to write cookie secret to %s: %s"), + self.cookie_secret_file, e) try: os.chmod(self.cookie_secret_file, 0o600) except OSError: @@ -1554,12 +1556,16 @@ class NotebookApp(JupyterApp): def write_server_info_file(self): """Write the result of server_info() to the JSON file info_file.""" - with open(self.info_file, 'w') as f: - json.dump(self.server_info(), f, indent=2, sort_keys=True) + try: + with open(self.info_file, 'w') as f: + json.dump(self.server_info(), f, indent=2, sort_keys=True) + except OSError as e: + self.log.error(_("Failed to write server-info to %s: %s"), + self.info_file, e) def remove_server_info_file(self): """Remove the nbserver-.json file created for this server. - + Ignores the error raised when the file has already been removed. """ try: