From 9a8ee70a99f88e26f450b95ba940dc6678f393dd Mon Sep 17 00:00:00 2001 From: domcge Date: Wed, 15 Jul 2026 16:46:03 -0400 Subject: [PATCH] Bug fix for loglines parameter throwing index out of range exception and add debug messages. Signed-off-by: domcge --- CHANGELOG.md | 18 ++++++++++++++++++ saspy/__init__.py | 5 +++++ saspy/sasioiom.py | 28 +++++++++++++++++++++++++++- saspy/version.py | 2 +- 4 files changed, 51 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fccc7e27..7f0996a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,23 @@ # Changelog +## [5.108.4] - 2026-07-15 + +### Added + +- `Enhancement` Add debug logging to IOM.submit method to help solve issue. + +### Changed + +- `None` Nothing Changed + +### Fixed + +- `Bug Fix` Make sure we don't attempt to use an index that is out of range when processing IOM.submit loglines parameter + +### Removed + +- `None` Nothing removed + ## [5.108.3] - 2026-07-08 ### Added diff --git a/saspy/__init__.py b/saspy/__init__.py index 47dc9774..2d2e0f06 100644 --- a/saspy/__init__.py +++ b/saspy/__init__.py @@ -34,6 +34,11 @@ logger.setLevel(logging.INFO) logger.propagate=False +IOMLogger = logging.getLogger("IOMLogger") +IOMLogger.addHandler(logging.StreamHandler(sys.stdout)) +IOMLogger.setLevel(logging.INFO) +IOMLogger.propagate=False + def _isnotebook(): try: shell = get_ipython().__class__.__name__ diff --git a/saspy/sasioiom.py b/saspy/sasioiom.py index ee2e821c..d6d0ab26 100644 --- a/saspy/sasioiom.py +++ b/saspy/sasioiom.py @@ -24,6 +24,11 @@ import io import atexit import re +#import debugpy +#debugpy.listen(5678) +#print("Waiting for debugger attach") +#debugpy.wait_for_client() +#debugpy.breakpoint() import logging logger = logging.getLogger('saspy') @@ -1089,6 +1094,7 @@ def submit(self, code: str, results: str ="html", prompt: dict = None, **kwargs) lstf.replace(chr(12), chr(10)).replace('', '').replace("font-size: x-small;", "font-size: normal;") + logf = logf.decode(errors='replace').replace(chr(12), chr(20)) self._log += logf final = logf.partition(logcodei) @@ -1098,6 +1104,16 @@ def submit(self, code: str, results: str ="html", prompt: dict = None, **kwargs) zz = z[0].rpartition("\nE3969440A681A24088859985" + prev +'\n') logd = zz[2].replace(mj.decode(), '') + IOMLogger = logging.getLogger("IOMLogger") + IOMLogger.debug("DEBUG raw log start ->\n{0}\n<- DEBUG - raw log end\n".format(logf)) + #IOMLogger.debug("DEBUG - final={0}\n".format(final)) + #IOMLogger.debug("DEBUG - types={0}\n".format(types)) + #IOMLogger.debug("DEBUG - z={0}\n".format(z)) + #IOMLogger.debug("DEBUG - prev={0}\n".format(prev)) + #IOMLogger.debug("DEBUG - zz={0}\n".format(zz)) + IOMLogger.debug("DEBUG - clean log start ->\n{0}\n<- DEBUG - clean log end\n".format(logd)) + IOMLogger.debug("DEBUG - clean lst start ->\n{0}\n<- DEBUG - clean lst end\n".format(lstd)) + if re.search(r'\nERROR[ \d-]*:', logd): warnings.warn("Noticed 'ERROR:' in LOG, you ought to take a look and see if there was a problem") self._sb.check_error_log = True @@ -1115,10 +1131,20 @@ def submit(self, code: str, results: str ="html", prompt: dict = None, **kwargs) sas_linetype_mapping types = types.partition(b"TomSaysTypes=")[2] types = list(types.rpartition(logcodeo)[0].decode(errors='replace')) + IOMLogger.debug("DEBUG - processing 'lines' - types={0}\n".format(types)) logl = [] logs = logd.split('\n') - for i in range(len(logs)): + + l_logs = len(logs) + l_types = len(types) + maxlines=l_logs if l_logs <= l_types else l_types + + IOMLogger.debug("DEBUG - processing 'lines' - l_logs={0}".format(l_logs)) + IOMLogger.debug("DEBUG - processing 'lines' - l_types={0}".format(l_types)) + IOMLogger.debug("DEBUG - processing 'lines' - maxlines={0}".format(maxlines)) + + for i in range(maxlines): logl.append({'line':logs[i], 'type':sas_linetype_mapping[int(types[i])]}) logd = logl diff --git a/saspy/version.py b/saspy/version.py index d71f1cc6..5148d47c 100644 --- a/saspy/version.py +++ b/saspy/version.py @@ -1 +1 @@ -__version__ = '5.108.3' +__version__ = '5.108.4'