🗑 Better error handling for a python bug
Non-ASCII host names under Windows are bad news for firing up an HTTPServer instance. We can't fix that, but we can display a better error message. See https://bugs.python.org/issue26227 Closes #3963
This commit is contained in:
1 parent
6913338dd9
commit
eff9793b33
2 files changed
+33
-4
No files matched your search
@@ -143,7 +143,7 @@ def run_server(
|
||||
method("There was a fatal error starting up OctoPrint.")
|
||||
|
||||
else:
|
||||
from octoprint.server import Server
|
||||
from octoprint.server import CannotStartServerException, Server
|
||||
|
||||
octoprint_server = Server(
|
||||
settings=settings,
|
||||
@@ -159,7 +159,16 @@ def run_server(
|
||||
allow_root=allow_root,
|
||||
octoprint_daemon=octoprint_daemon,
|
||||
)
|
||||
octoprint_server.run()
|
||||
|
||||
try:
|
||||
octoprint_server.run()
|
||||
except CannotStartServerException as e:
|
||||
logger = logging.getLogger("octoprint.startup").fatal
|
||||
echo = lambda x: click.echo(x, err=True)
|
||||
|
||||
for method in logger, echo:
|
||||
method(str(e))
|
||||
method("There was a fatal error starting up OctoPrint.")
|
||||
|
||||
|
||||
# ~~ server options
|
||||
|
||||
@@ -2441,9 +2441,25 @@ class Server(object):
|
||||
try:
|
||||
self._intermediary_server.server_bind()
|
||||
self._intermediary_server.server_activate()
|
||||
except Exception:
|
||||
except Exception as exc:
|
||||
self._intermediary_server.server_close()
|
||||
raise
|
||||
|
||||
if isinstance(exc, UnicodeDecodeError) and sys.platform == "win32":
|
||||
# we end up here if the hostname contains non-ASCII characters due to
|
||||
# https://bugs.python.org/issue26227 - tell the user they need
|
||||
# to either change their hostname or read up other options in
|
||||
# https://github.com/OctoPrint/OctoPrint/issues/3963
|
||||
raise CannotStartServerException(
|
||||
"OctoPrint cannot start due to a Python bug "
|
||||
"(https://bugs.python.org/issue26227). Your "
|
||||
"computer's host name contains non-ASCII characters. "
|
||||
"Please either change your computer's host name to "
|
||||
"contain only ASCII characters, or take a look at "
|
||||
"https://github.com/OctoPrint/OctoPrint/issues/3963 for "
|
||||
"other options."
|
||||
)
|
||||
else:
|
||||
raise
|
||||
|
||||
def serve():
|
||||
try:
|
||||
@@ -2656,3 +2672,7 @@ class LifecycleManager(object):
|
||||
for event in events:
|
||||
if callback in self._plugin_lifecycle_callbacks[event]:
|
||||
self._plugin_lifecycle_callbacks[event].remove(callback)
|
||||
|
||||
|
||||
class CannotStartServerException(Exception):
|
||||
pass
|
||||
Reference in new issue
Block a user