morshu-server: report startup errors in Discord

This commit is contained in:
2026-06-06 19:56:16 -05:00
parent 561cec8bee
commit 579c4c0a9f
+13 -17
View File
@@ -516,21 +516,19 @@ class TtsToy(Cog):
except Exception as e: except Exception as e:
log.exception(f"Error stopping DECTalk server: {e}") log.exception(f"Error stopping DECTalk server: {e}")
async def _start_morshu_server(self) -> bool: async def _start_morshu_server(self) -> tuple:
"""Start the built-in Morshu TTS server.""" """Start the built-in Morshu TTS server. Returns (success, error_msg)."""
try: try:
if self.morshu_process and self.morshu_process.poll() is None: if self.morshu_process and self.morshu_process.poll() is None:
log.info("Morshu server already running") log.info("Morshu server already running")
return True return True, None
if not self.morshu_dir.exists(): if not self.morshu_dir.exists():
log.error(f"Morshu server directory not found: {self.morshu_dir}") return False, f"Directory not found: {self.morshu_dir}"
return False
server_py = self.morshu_dir / "server.py" server_py = self.morshu_dir / "server.py"
if not server_py.exists(): if not server_py.exists():
log.error(f"Morshu server not found: {server_py}") return False, f"server.py not found: {server_py}"
return False
env = os.environ.copy() env = os.environ.copy()
env['PORT'] = str(self.morshu_port) env['PORT'] = str(self.morshu_port)
@@ -552,18 +550,15 @@ class TtsToy(Cog):
if self.morshu_process.poll() is not None: if self.morshu_process.poll() is not None:
stderr = self.morshu_process.stderr.read() stderr = self.morshu_process.stderr.read()
stdout = self.morshu_process.stdout.read() stdout = self.morshu_process.stdout.read()
log.error(f"Morshu server failed to start (exit {self.morshu_process.returncode})") err = stderr or stdout or "Unknown error"
if stderr: log.error(f"Morshu server failed (exit {self.morshu_process.returncode}): {err}")
log.error(f"Morshu stderr: {stderr}") return False, err
if stdout:
log.error(f"Morshu stdout: {stdout}")
return False
log.info(f"Morshu server started on port {self.morshu_port}") log.info(f"Morshu server started on port {self.morshu_port}")
return True return True, None
except Exception as e: except Exception as e:
log.exception(f"Failed to start Morshu server: {e}") log.exception(f"Failed to start Morshu server: {e}")
return False return False, str(e)
async def _stop_morshu_server(self): async def _stop_morshu_server(self):
"""Stop the built-in Morshu server.""" """Stop the built-in Morshu server."""
@@ -2140,7 +2135,7 @@ class TtsToy(Cog):
"""Start the built-in Morshu TTS server.""" """Start the built-in Morshu TTS server."""
await ctx.send("🚀 Starting Morshu server...") await ctx.send("🚀 Starting Morshu server...")
success = await self._start_morshu_server() success, error = await self._start_morshu_server()
if success: if success:
await ctx.send( await ctx.send(
@@ -2148,7 +2143,8 @@ class TtsToy(Cog):
f"Switch to Morshu mode: `{ctx.clean_prefix}ttstoy mode morshu`" f"Switch to Morshu mode: `{ctx.clean_prefix}ttstoy mode morshu`"
) )
else: else:
await ctx.send("❌ Failed to start Morshu server. Check bot logs.") err_msg = (error or "Unknown error")[:1500]
await ctx.send(f"❌ Failed to start Morshu server:\n```\n{err_msg}\n```")
@ttstoy_group.command(name="morshustop") @ttstoy_group.command(name="morshustop")
@commands.is_owner() @commands.is_owner()