diff --git a/webserver/openplc.py b/webserver/openplc.py index f22bf7a..f0d8a9c 100644 --- a/webserver/openplc.py +++ b/webserver/openplc.py @@ -137,9 +137,9 @@ class runtime: else: # No debug info... probably a program generated from the old editor. Use the blank debug info just to compile the program - f = open('./core/debug.blank', "r") - c_debug = f.read() - f.close() + with open('./core/debug.blank', "r") as f: + c_debug = f.read() + f.close() # Write c_debug file with open('./core/debug.cpp', "w") as f: diff --git a/webserver/webserver.py b/webserver/webserver.py index f0ea4b9..4708fcc 100644 --- a/webserver/webserver.py +++ b/webserver/webserver.py @@ -59,11 +59,17 @@ def restapi_callback_get(argument: str, data: dict) -> dict: elif argument == "compilation-status": status = openplc_runtime.compilation_status_str + if status == "": + return {"compilation-status": "No compilation in progress"} return {"compilation-status": status} elif argument == "compilation-logs": - logs = openplc_runtime.compilation_status() - return {"compilation-logs": logs} + try: + logs = openplc_runtime.compilation_status() + return {"compilation-logs": logs} + except Exception as e: + logger.error(f"Error retrieving compilation logs: {e}") + return {"error": str(e)} elif argument == "status": return {"current_status": "operational", "details": data}