Fix: tools.py verbose errors and path mapping
This commit is contained in:
11
tools.py
11
tools.py
@@ -14,13 +14,14 @@ def run_bash_command(command: str) -> str:
|
|||||||
text=True,
|
text=True,
|
||||||
timeout=120 # Aumentado para comandos mais pesados
|
timeout=120 # Aumentado para comandos mais pesados
|
||||||
)
|
)
|
||||||
|
|
||||||
output = result.stdout.strip()
|
output = result.stdout.strip()
|
||||||
error = result.stderr.strip()
|
error = result.stderr.strip()
|
||||||
|
|
||||||
if result.returncode != 0:
|
if result.returncode != 0:
|
||||||
return f"ERRO ({result.returncode}):\n{error}"
|
return f"ERRO ({result.returncode}): {error if error else 'Nada no stderr'}"
|
||||||
|
|
||||||
return output if output else "Comando executado com sucesso (sem saída)."
|
return output if output else "Sucesso (vazio)"
|
||||||
except subprocess.TimeoutExpired:
|
except subprocess.TimeoutExpired:
|
||||||
return "ERRO: O comando demorou muito e foi cancelado (timeout)."
|
return "ERRO: O comando demorou muito e foi cancelado (timeout)."
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -44,9 +45,13 @@ def get_system_health() -> str:
|
|||||||
def read_vps_file(filepath: str) -> str:
|
def read_vps_file(filepath: str) -> str:
|
||||||
"""Lê um arquivo do sistema de arquivos da VPS através do mapeamento /host_root."""
|
"""Lê um arquivo do sistema de arquivos da VPS através do mapeamento /host_root."""
|
||||||
host_path = f"/host_root{filepath}" if not filepath.startswith("/host_root") else filepath
|
host_path = f"/host_root{filepath}" if not filepath.startswith("/host_root") else filepath
|
||||||
|
# Se ainda assim não começar com /host_root e não for absoluto para o container, tentamos prefixar
|
||||||
|
if not host_path.startswith("/host_root") and filepath.startswith("/"):
|
||||||
|
host_path = "/host_root" + filepath
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if not os.path.exists(host_path):
|
if not os.path.exists(host_path):
|
||||||
return f"Erro: Arquivo {filepath} não encontrado no host."
|
return f"Erro: Arquivo {filepath} não encontrado no host (Caminho tentado: {host_path})."
|
||||||
with open(host_path, 'r') as f:
|
with open(host_path, 'r') as f:
|
||||||
return f.read(2000) # Limite para não estourar o contexto
|
return f.read(2000) # Limite para não estourar o contexto
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user