moonraker: report a 'warnings' field in "/server/info"

This allows clients to display a list of warnings that Moonraker detects.   Previously this info was only logged.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Arksine 2021-05-19 20:32:16 -04:00
parent 36aec50bce
commit ceae5bb88b
2 changed files with 18 additions and 8 deletions

View File

@ -143,17 +143,19 @@ class ConfigHelper:
def validate_config(self) -> None:
for sect in self.orig_sections:
if sect not in self.parsed:
logging.warn(
f"Invalid config section [{sect}] detected. In "
"the future this will result in a startup error")
self.server.add_warning(
f"Unparsed config section [{sect}] detected. This "
"may be the result of a component that failed to "
"load. In the future this will result in a startup "
"error.")
continue
parsed_opts = self.parsed[sect]
for opt, val in self.config.items(sect):
if opt not in parsed_opts:
logging.warn(
f"Invalid option '{opt}' detected in section "
f"[{sect}]. In the future this will result in a "
"startup error.")
self.server.add_warning(
f"Invalid config option '{opt}' detected in section "
f"[{sect}]. Remove the option to resolve this issue. "
"In the future this will result in a startup error.")
def get_configuration(server: Server,
system_args: Namespace

View File

@ -93,6 +93,7 @@ class Server:
self.klippy_disconnect_evt: Optional[Event] = None
self.subscriptions: Dict[Subscribable, Dict[str, Any]] = {}
self.failed_components: List[str] = []
self.warnings: List[str] = []
# Server/IOLoop
self.server_running: bool = False
@ -156,6 +157,11 @@ class Server:
if log and item is not None:
logging.info(item)
def add_warning(self, warning: str, log: bool = True) -> None:
self.warnings.append(warning)
if log:
logging.warn(warning)
# ***** Component Management *****
def _load_components(self, config: confighelper.ConfigHelper) -> None:
# load core components
@ -586,7 +592,9 @@ class Server:
'failed_components': self.failed_components,
'plugins': list(self.components.keys()),
'failed_plugins': self.failed_components,
'registered_directories': reg_dirs}
'registered_directories': reg_dirs,
'warnings': self.warnings
}
async def _handle_config_request(self,
web_request: WebRequest