Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/workflow/ParameterManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,40 @@ def get_parameters_from_json(self) -> dict:
st.error("**ERROR**: Attempting to load an invalid JSON parameter file. Reset to defaults.")
return {}

def get_topp_parameters(self, tool: str) -> dict:
"""
Get all parameters for a TOPP tool, merging defaults with user values.

Args:
tool: Name of the TOPP tool (e.g., "CometAdapter")

Returns:
Dict with parameter names as keys (without tool prefix) and their values.
Returns empty dict if ini file doesn't exist.
"""
ini_path = Path(self.ini_dir, f"{tool}.ini")
if not ini_path.exists():
return {}

# Load defaults from ini file
param = poms.Param()
poms.ParamXMLFile().load(str(ini_path), param)
Comment on lines +116 to +118
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Add error handling for corrupted ini files.

The ParamXMLFile().load() call lacks error handling for corrupted or malformed ini files, which could raise an unhandled exception and disrupt the application. Compare this with get_parameters_from_json() (lines 94-99), which includes a try-except block to handle invalid JSON files gracefully.

🔎 Proposed fix with error handling
     # Load defaults from ini file
     param = poms.Param()
-    poms.ParamXMLFile().load(str(ini_path), param)
+    try:
+        poms.ParamXMLFile().load(str(ini_path), param)
+    except Exception:
+        st.error(f"**ERROR**: Failed to load ini file for tool '{tool}'. File may be corrupted.")
+        return {}
🤖 Prompt for AI Agents
In src/workflow/ParameterManager.py around lines 116-118, the
poms.ParamXMLFile().load(...) call lacks error handling for malformed/corrupted
ini files; wrap that load call in a try/except block (matching the pattern used
in get_parameters_from_json at lines 94-99), catch parsing/file exceptions
(catch Exception as e if no specific poms exception is available), log the error
including exception details (using the module logger or logging.exception), and
then fall back to an empty/default poms.Param() or return/continue gracefully so
the application does not crash.


# Build dict from ini (extract short key names)
prefix = f"{tool}:1:"
full_params = {}
for key in param.keys():
key_str = key.decode() if isinstance(key, bytes) else str(key)
if prefix in key_str:
short_key = key_str.split(prefix, 1)[1]
full_params[short_key] = param.getValue(key)

# Override with user-modified values from JSON
user_params = self.get_parameters_from_json().get(tool, {})
full_params.update(user_params)

return full_params

def reset_to_default_parameters(self) -> None:
"""
Resets the parameters to their default values by deleting the custom parameters
Expand Down