mirror of
https://github.com/MarekWo/mc-webui.git
synced 2026-03-28 17:42:45 +01:00
fix: Parse node_discover output correctly by removing prompt
The .node_discover command returns prompt line before JSON array. Added parser to extract only JSON by finding first '[' character and ignoring everything before it (including 'MarWoj|* .node_discover'). Fixes JSON parsing error: 'Expecting value: line 1 column 1 (char 0)' 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -395,8 +395,21 @@ def node_discover() -> Tuple[bool, List[Dict]]:
|
||||
return False, []
|
||||
|
||||
try:
|
||||
# Parse JSON array from stdout
|
||||
nodes = json.loads(stdout)
|
||||
# Clean output: remove prompt lines (e.g., "MarWoj|* .node_discover")
|
||||
# and extract only the JSON array
|
||||
cleaned_output = stdout.strip()
|
||||
|
||||
# Find the start of JSON array (first '[')
|
||||
json_start = cleaned_output.find('[')
|
||||
if json_start == -1:
|
||||
logger.error(f"No JSON array found in output: {stdout}")
|
||||
return False, []
|
||||
|
||||
# Extract JSON from first '[' to end
|
||||
json_str = cleaned_output[json_start:]
|
||||
|
||||
# Parse JSON array
|
||||
nodes = json.loads(json_str)
|
||||
if not isinstance(nodes, list):
|
||||
logger.error(f"node_discover returned non-array: {stdout}")
|
||||
return False, []
|
||||
|
||||
Reference in New Issue
Block a user