Small fixes and bigger library

This commit is contained in:
2026-08-18 14:22:01 +02:00
parent 60a30d4ee3
commit 1d535c1f5b
21 changed files with 935 additions and 41 deletions

View File

@@ -24,6 +24,14 @@ class ProcessResult:
stdout: str
stderr: str
def diagnostics(self) -> str:
sections = []
if self.stdout.strip():
sections.append(f"OpenModelica output:\n{self.stdout.strip()}")
if self.stderr.strip():
sections.append(f"OpenModelica errors:\n{self.stderr.strip()}")
return "\n\n".join(sections)
class OpenModelicaError(RuntimeError):
"""Raised when OMC cannot start or reports a failure."""
@@ -80,7 +88,7 @@ class OpenModelicaRunner:
f"OpenModelica timed out after {error.timeout} seconds"
) from error
if result.return_code != 0:
details = result.stderr.strip() or result.stdout.strip()
details = result.diagnostics()
suffix = f": {details}" if details else ""
raise OpenModelicaError(
f"OpenModelica exited with status {result.return_code}{suffix}"
@@ -128,7 +136,7 @@ class OpenModelicaRunner:
continue
result = ProcessResult(command=tuple(command), return_code=process.returncode, stdout=stdout, stderr=stderr)
if result.return_code != 0:
details = result.stderr.strip() or result.stdout.strip()
details = result.diagnostics()
suffix = f": {details}" if details else ""
raise OpenModelicaError(f"simulation exited with status {result.return_code}{suffix}")
return result