Repository: troycomi/reportseff

Issue:
Multi-line SubmitLine breaks parsing
**Describe the bug**
Multi-line SubmitLines break the parser

**To Reproduce**
Steps to reproduce the behavior:
1. submit a job whose SubmitLine is multiple lines, for example
```
srun bash -c "echo hello &&      (press enter)
echo goodbye"
```
2. ask reportseff for a report including the SubmitLine: `reportseff  1234 --format="+SumbitLine"`
3. Receive python stack trace.
```
  File "/home/user/.local/lib/python3.10/site-packages/reportseff/job_collection.py", line 204, in process_entry
    job_id = entry["JobID"].split(".")[0]
KeyError: 'JobID'`
```

**Expected behavior**
Not crash

**Desktop (please complete the following information):**
 - OS: CentOS Linux release 7.9.2009 (Core)
 - Version:
 ```
commit b826d801abc204a13c606f904bae6741885b8e8d (HEAD -> main, tag: v2.8.0, origin/main, origin/HEAD)
Author: Joel Lafond-Lapalme <joel.lafond.lapalme@gmail.com>
Date:   Thu Oct 3 10:55:00 2024 -0400
```

**Debug Output**
```
^|^1^|^00:00:02^|^59374177^|^59374177^|^^|^1^|^^|^2097M^|^COMPLETED^|^srun  --interactive --pty bash -c echo hello &&
echo goodbye^|^20:00:00^|^00:00.042
^|^1^|^00:00:02^|^59374177.interactive^|^59374177.interactive^|^0^|^1^|^1^|^^|^COMPLETED^|^srun  --interactive --pty bash -c echo hello &&
echo goodbye^|^^|^00:00.039
^|^1^|^00:00:02^|^59374177.extern^|^59374177.extern^|^0^|^1^|^1^|^^|^COMPLETED^|^^|^^|^00:00.002

Error processing entry: {'AdminComment': 'echo goodbye', 'AllocCPUS': '20:00:00', 'Elapsed': '00:00.042'}
```

**Additional context**
`sacct` is returning the data split on multiple lines. I _think_ it's still properly setting up the delimiters, but I don't have the resources at the moment to come up with a good solution (maybe checking whether a line has too few columns, then trying to merge the next line if so?).

Discussion:

Patch:
diff --git a/pyproject.toml b/pyproject.toml
index 0019748..38753bd 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,6 +1,6 @@
 [tool.poetry]
 name = "reportseff"
-version = "2.8.1"
+version = "2.8.2"
 description= "Tablular seff output"
 authors = ["Troy Comi <troycomi@gmail.com>"]
 license = "MIT"
diff --git a/src/reportseff/db_inquirer.py b/src/reportseff/db_inquirer.py
index 2e11314..1d1089d 100644
--- a/src/reportseff/db_inquirer.py
+++ b/src/reportseff/db_inquirer.py
@@ -271,7 +271,11 @@ class SacctInquirer(BaseInquirer):
             raise RuntimeError(msg) from error
 
         sacct_line_split = re.compile(r"\^\|\^\n")
-        lines = sacct_line_split.split(cmd_result.stdout)
+        # convert newlines to printable \n
+        lines = [
+            line.replace("\n", "\\n")
+            for line in sacct_line_split.split(cmd_result.stdout)
+        ]
         if debug_cmd is not None:
             debug_cmd("\n".join(line.replace("\n", "\\n") for line in lines))
 


Test patch:
diff --git a/tests/test_db_inquirer.py b/tests/test_db_inquirer.py
index 5574aef..6aec443 100644
--- a/tests/test_db_inquirer.py
+++ b/tests/test_db_inquirer.py
@@ -833,7 +833,7 @@ def test_sacct_newline_jobs_issue_63(sacct, mocker):
     )
     result = sacct.get_db_output("c1 c2".split(), "j1 j2 j3".split())
     assert result == [
-        {"c1": "c1 \n j1", "c2": "c2j1"},
+        {"c1": "c1 \\n j1", "c2": "c2j1"},
         {"c1": "c1j2", "c2": "c2j2"},
         {"c1": "c1j3", "c2": "c2j3"},
     ]