Better diagnostic for permission denied on bind() for low ports.

This commit is contained in:
L. Kärkkäinen 2023-09-05 19:28:46 +01:00
parent b9b54a2eda
commit abdb5cb531

View File

@ -112,6 +112,16 @@ def configure_socket(
server_settings["port"], server_settings["port"],
backlog=backlog, backlog=backlog,
) )
except PermissionError as e:
p = server_settings["port"]
if p and server_settings["port"] < 1024:
addr = f"{server_settings['host']}:{p}"
e = ServerError(
f"Permission denied binding to {addr}.\n\n"
"Use `sudo sanic` to run on a privileged port.\n"
)
e.quiet = True
raise e from None
except OSError as e: # no cov except OSError as e: # no cov
error = ServerError( error = ServerError(
f"Sanic server could not start: {e}.\n\n" f"Sanic server could not start: {e}.\n\n"