mirror of
https://github.com/migatu/conjurer.git
synced 2026-07-14 21:38:38 +00:00
disable exc masking
This commit is contained in:
+8
-4
@@ -21,6 +21,7 @@ class LatexModule(commands.Cog):
|
||||
def __init__(self, bot: commands.Bot, logger_name: str):
|
||||
self.bot = bot
|
||||
self.logger = logging.getLogger(logger_name)
|
||||
self.logger_name = logger_name
|
||||
|
||||
# -------- /tex (PDF + diagnoza; log -> debug logger) --------
|
||||
@commands.hybrid_command(
|
||||
@@ -44,7 +45,7 @@ class LatexModule(commands.Cog):
|
||||
try:
|
||||
data = await att.read()
|
||||
self.logger.info("LaTeX read %s bytes from %s", len(data), att.filename)
|
||||
res = await compile_single_tex_bytes(data, att.filename, LATEX_TEX_ENGINE, LATEX_MAX_COMPILE_SECONDS, logger=self.logger)
|
||||
res = await compile_single_tex_bytes(data, att.filename, LATEX_TEX_ENGINE, LATEX_MAX_COMPILE_SECONDS, logger=self.logger_name)
|
||||
self.logger.info("LaTeX result for %s: %s", att.filename, res)
|
||||
self.logger.info("LaTeX log (%s)\n%s", att.filename, (res["log_text"] or "")[-2000:])
|
||||
if res["ok"] and res["pdf_bytes"]:
|
||||
@@ -61,11 +62,13 @@ class LatexModule(commands.Cog):
|
||||
excerpt = data.decode("utf-8", errors="ignore")[:4000]
|
||||
except Exception:
|
||||
excerpt = ""
|
||||
advice = await ask_openai_diagnosis(res["log_text"] or "", excerpt, OPENAI_MODEL, logger=self.logger)
|
||||
advice = await ask_openai_diagnosis(res["log_text"] or "", excerpt, OPENAI_MODEL, logger=self.logger_name)
|
||||
parts.append(f"❌ `{att.filename}` — błąd kompilacji.\nDiagnoza:\n{advice}")
|
||||
raise
|
||||
except Exception as e:
|
||||
self.logger.info("Exception %s: %s", att.filename, e)
|
||||
parts.append(f"⚠️ `{att.filename}` — wyjątek (szczegóły w logu).")
|
||||
raise
|
||||
|
||||
content = f"**LaTeX** — {len(atts)} plik(ów). Model: `{OPENAI_MODEL}`\n\n" + "\n\n".join(parts)
|
||||
await ctx.reply(content if len(content)<1900 else content[:1900]+"…", files=files, mention_author=False)
|
||||
@@ -90,7 +93,7 @@ class LatexModule(commands.Cog):
|
||||
for att in atts:
|
||||
try:
|
||||
data = await att.read()
|
||||
res = await compile_single_tex_bytes(data, att.filename, LATEX_TEX_ENGINE, LATEX_MAX_COMPILE_SECONDS, logger=self.logger)
|
||||
res = await compile_single_tex_bytes(data, att.filename, LATEX_TEX_ENGINE, LATEX_MAX_COMPILE_SECONDS, logger=self.logger_name)
|
||||
self.logger.debug("LaTeX CLEAN (%s)\n%s", att.filename, (res["log_text"] or "")[-2000:])
|
||||
if res["ok"] and res["pdf_bytes"]:
|
||||
b = io.BytesIO(res["pdf_bytes"])
|
||||
@@ -103,6 +106,7 @@ class LatexModule(commands.Cog):
|
||||
except Exception as e:
|
||||
self.logger.debug("CLEAN exception %s: %s", att.filename, e)
|
||||
parts.append(f"⚠️ `{att.filename}` — wyjątek (log w debug).")
|
||||
raise
|
||||
|
||||
await ctx.reply("**LaTeX clean** — " + ", ".join(parts), files=files, mention_author=False)
|
||||
|
||||
@@ -121,7 +125,7 @@ class LatexModule(commands.Cog):
|
||||
return await interaction.followup.send(f"ZIP > {LATEX_MAX_ZIP_MB} MiB — za duży.", ephemeral=True)
|
||||
|
||||
data = await archive.read()
|
||||
out_zip_bytes, failed = await compile_zip_to_zip(data, LATEX_TEX_ENGINE, LATEX_MAX_COMPILE_SECONDS, logger=self.logger)
|
||||
out_zip_bytes, failed = await compile_zip_to_zip(data, LATEX_TEX_ENGINE, LATEX_MAX_COMPILE_SECONDS, logger=self.logger_name)
|
||||
if not out_zip_bytes and failed:
|
||||
return await interaction.followup.send("Brak PDF-ów. " + "; ".join(failed[:10]), ephemeral=True)
|
||||
|
||||
|
||||
+4
-4
@@ -30,7 +30,7 @@ def is_tex_attachment(att, max_mb: int) -> bool:
|
||||
|
||||
|
||||
async def run_latex_two_passes(
|
||||
tex_filename: str, workdir: Path, tex_engine: str, timeout_sec: int, logger=None
|
||||
tex_filename: str, workdir: Path, tex_engine: str, timeout_sec: int, logger:str=None
|
||||
) -> Tuple[bool, str, Path]:
|
||||
cmd = f"{tex_engine} -interaction=nonstopmode -halt-on-error -file-line-error -no-shell-escape {shlex.quote(tex_filename)}"
|
||||
logger = logging.getLogger(logger) if logger else None
|
||||
@@ -52,7 +52,7 @@ async def run_latex_two_passes(
|
||||
try:
|
||||
proc.kill()
|
||||
except Exception:
|
||||
pass
|
||||
raise
|
||||
return 124, f"[Timeout] Compilation exceeded {timeout_sec}s.\n"
|
||||
|
||||
logs: List[str] = []
|
||||
@@ -75,7 +75,7 @@ async def run_latex_two_passes(
|
||||
|
||||
|
||||
async def compile_single_tex_bytes(
|
||||
tex_bytes: bytes, filename: str, tex_engine: str, timeout_sec: int, logger=None
|
||||
tex_bytes: bytes, filename: str, tex_engine: str, timeout_sec: int, logger:str=None
|
||||
) -> Dict[str, Optional[object]]:
|
||||
if not is_safe_tex_name(filename):
|
||||
return {
|
||||
@@ -107,7 +107,7 @@ async def compile_single_tex_bytes(
|
||||
|
||||
|
||||
async def compile_zip_to_zip(
|
||||
zip_bytes: bytes, tex_engine: str, timeout_sec: int, logger=None
|
||||
zip_bytes: bytes, tex_engine: str, timeout_sec: int, logger:str=None
|
||||
) -> Tuple[bytes, List[str]]:
|
||||
failed: List[str] = []
|
||||
out_pdf_paths: List[Path] = []
|
||||
|
||||
Reference in New Issue
Block a user