Skip to content

Commit edec31d

Browse files
refactor(cli): update MCP exception handlers to use report_error
1 parent 20b165a commit edec31d

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

hatch/cli/cli_mcp.py

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
ColumnDef,
6868
ValidationError,
6969
format_validation_error,
70+
ResultReporter,
7071
)
7172

7273

@@ -141,7 +142,8 @@ def handle_mcp_discover_hosts(args: Namespace) -> int:
141142
print(formatter.render())
142143
return EXIT_SUCCESS
143144
except Exception as e:
144-
print(f"Error discovering hosts: {e}")
145+
reporter = ResultReporter("hatch mcp discover hosts")
146+
reporter.report_error("Failed to discover hosts", details=[f"Reason: {str(e)}"])
145147
return EXIT_ERROR
146148

147149

@@ -220,7 +222,8 @@ def handle_mcp_discover_servers(args: Namespace) -> int:
220222

221223
return EXIT_SUCCESS
222224
except Exception as e:
223-
print(f"Error discovering servers: {e}")
225+
reporter = ResultReporter("hatch mcp discover servers")
226+
reporter.report_error("Failed to discover servers", details=[f"Reason: {str(e)}"])
224227
return EXIT_ERROR
225228

226229

@@ -360,7 +363,8 @@ def handle_mcp_list_hosts(args: Namespace) -> int:
360363
print(formatter.render())
361364
return EXIT_SUCCESS
362365
except Exception as e:
363-
print(f"Error listing hosts: {e}")
366+
reporter = ResultReporter("hatch mcp list hosts")
367+
reporter.report_error("Failed to list hosts", details=[f"Reason: {str(e)}"])
364368
return EXIT_ERROR
365369

366370

@@ -503,7 +507,8 @@ def handle_mcp_list_servers(args: Namespace) -> int:
503507
print(formatter.render())
504508
return EXIT_SUCCESS
505509
except Exception as e:
506-
print(f"Error listing servers: {e}")
510+
reporter = ResultReporter("hatch mcp list servers")
511+
reporter.report_error("Failed to list servers", details=[f"Reason: {str(e)}"])
507512
return EXIT_ERROR
508513

509514

@@ -722,7 +727,8 @@ def handle_mcp_show_hosts(args: Namespace) -> int:
722727

723728
return EXIT_SUCCESS
724729
except Exception as e:
725-
print(f"Error showing host configurations: {e}")
730+
reporter = ResultReporter("hatch mcp show hosts")
731+
reporter.report_error("Failed to show host configurations", details=[f"Reason: {str(e)}"])
726732
return EXIT_ERROR
727733

728734

@@ -935,7 +941,8 @@ def handle_mcp_show_servers(args: Namespace) -> int:
935941

936942
return EXIT_SUCCESS
937943
except Exception as e:
938-
print(f"Error showing server configurations: {e}")
944+
reporter = ResultReporter("hatch mcp show servers")
945+
reporter.report_error("Failed to show server configurations", details=[f"Reason: {str(e)}"])
939946
return EXIT_ERROR
940947

941948

@@ -1055,7 +1062,8 @@ def handle_mcp_backup_restore(args: Namespace) -> int:
10551062
return EXIT_ERROR
10561063

10571064
except Exception as e:
1058-
print(f"Error restoring backup: {e}")
1065+
reporter = ResultReporter("hatch mcp backup restore")
1066+
reporter.report_error("Failed to restore backup", details=[f"Reason: {str(e)}"])
10591067
return EXIT_ERROR
10601068

10611069

@@ -1141,7 +1149,8 @@ def handle_mcp_backup_list(args: Namespace) -> int:
11411149

11421150
return EXIT_SUCCESS
11431151
except Exception as e:
1144-
print(f"Error listing backups: {e}")
1152+
reporter = ResultReporter("hatch mcp backup list")
1153+
reporter.report_error("Failed to list backups", details=[f"Reason: {str(e)}"])
11451154
return EXIT_ERROR
11461155

11471156

@@ -1260,7 +1269,8 @@ def handle_mcp_backup_clean(args: Namespace) -> int:
12601269
return EXIT_SUCCESS
12611270

12621271
except Exception as e:
1263-
print(f"Error cleaning backups: {e}")
1272+
reporter = ResultReporter("hatch mcp backup clean")
1273+
reporter.report_error("Failed to clean backups", details=[f"Reason: {str(e)}"])
12641274
return EXIT_ERROR
12651275

12661276

@@ -1527,7 +1537,8 @@ def handle_mcp_configure(args: Namespace) -> int:
15271537
return EXIT_ERROR
15281538

15291539
except Exception as e:
1530-
print(f"Error configuring MCP server: {e}")
1540+
reporter = ResultReporter("hatch mcp configure")
1541+
reporter.report_error("Failed to configure MCP server", details=[f"Reason: {str(e)}"])
15311542
return EXIT_ERROR
15321543

15331544

@@ -1607,7 +1618,8 @@ def handle_mcp_remove(args: Namespace) -> int:
16071618
return EXIT_ERROR
16081619

16091620
except Exception as e:
1610-
print(f"Error removing MCP server: {e}")
1621+
reporter = ResultReporter("hatch mcp remove")
1622+
reporter.report_error("Failed to remove MCP server", details=[f"Reason: {str(e)}"])
16111623
return EXIT_ERROR
16121624

16131625

@@ -1729,7 +1741,8 @@ def handle_mcp_remove_server(args: Namespace) -> int:
17291741
return EXIT_ERROR
17301742

17311743
except Exception as e:
1732-
print(f"Error removing MCP server: {e}")
1744+
reporter = ResultReporter("hatch mcp remove-server")
1745+
reporter.report_error("Failed to remove MCP server", details=[f"Reason: {str(e)}"])
17331746
return EXIT_ERROR
17341747

17351748

@@ -1815,7 +1828,8 @@ def handle_mcp_remove_host(args: Namespace) -> int:
18151828
return EXIT_ERROR
18161829

18171830
except Exception as e:
1818-
print(f"Error removing host configuration: {e}")
1831+
reporter = ResultReporter("hatch mcp remove-host")
1832+
reporter.report_error("Failed to remove host configuration", details=[f"Reason: {str(e)}"])
18191833
return EXIT_ERROR
18201834

18211835

@@ -1935,5 +1949,6 @@ def handle_mcp_sync(args: Namespace) -> int:
19351949
format_validation_error(ValidationError(str(e)))
19361950
return EXIT_ERROR
19371951
except Exception as e:
1938-
print(f"Error during synchronization: {e}")
1952+
reporter = ResultReporter("hatch mcp sync")
1953+
reporter.report_error("Failed to synchronize", details=[f"Reason: {str(e)}"])
19391954
return EXIT_ERROR

0 commit comments

Comments
 (0)