From 3d962638c6de57aa35e3d8597c987d512299a258 Mon Sep 17 00:00:00 2001 From: Tom Weber Date: Fri, 6 Sep 2024 15:42:43 -0400 Subject: [PATCH] fix issue 615 --- saspy/sas_magic.py | 6 +++--- saspy/sasbase.py | 2 +- saspy/sasdata.py | 8 ++++---- saspy/sasiocom.py | 3 ++- saspy/sasiohttp.py | 3 ++- saspy/sasioiom.py | 7 ++++--- saspy/sasiostdio.py | 2 +- saspy/sasproccommons.py | 2 +- 8 files changed, 18 insertions(+), 15 deletions(-) diff --git a/saspy/sas_magic.py b/saspy/sas_magic.py index b3f2df80..5680c51a 100644 --- a/saspy/sas_magic.py +++ b/saspy/sas_magic.py @@ -52,7 +52,7 @@ def SAS(self, line, cell): set sashelp.cars; run; """ - + mva = self.mva if len(line): # session supplied names = line.split('.') @@ -99,7 +99,7 @@ def SAS(self, line, cell): res = mva.submit(cell) dis = self._which_display(mva, res['LOG'], res['LST']) - if len(line)>0: # Restore SAS options + if len(line)>0: # Restore SAS options mva.submit(restoreOpts) return dis @@ -178,7 +178,7 @@ def _which_display(mva, log, output): for line in lines: i += 1 e = [] - if line[mva.logoffset:].startswith('ERROR'): + if re.search(r'^ERROR[ \d-]*:', line[mva.logoffset:]): e = lines[(max(i - 15, 0)):(min(i + 16, len(lines)))] elog = elog + e if len(elog) == 0 and len(output) > lst_len: # no error and LST output diff --git a/saspy/sasbase.py b/saspy/sasbase.py index 3941513e..c1de9248 100644 --- a/saspy/sasbase.py +++ b/saspy/sasbase.py @@ -682,7 +682,7 @@ def __init__(self, **kwargs): if self.sascfg.autoexec: self._io.submit(self.sascfg.autoexec) - # this is to support parsing the log to fring log records w/ 'ERROR' when diagnostic logging is enabled. + # this is to support parsing the log to find log records w/ 'ERROR' when diagnostic logging is enabled. # in thi scase the log can have prefix and/or suffix info so the 'regular' log data is in the middle, not left justified if self.sascfg.mode in ['STDIO', 'SSH', '']: ll = self._io.submit("""data _null_; file STDERR; put %upcase('col0REG='); diff --git a/saspy/sasdata.py b/saspy/sasdata.py index cec45d32..2c34039b 100644 --- a/saspy/sasdata.py +++ b/saspy/sasdata.py @@ -153,7 +153,7 @@ def _is_valid(self): def _checkLogForError(self, log): lines = re.split(r'[\n]\s*', log) for line in lines: - if line[self.sas.logoffset:].startswith('ERROR'): + if re.search(r'^ERROR[ \d-]*:', line[self.sas.logoffset:]): return (False, line) return (True, '') @@ -508,7 +508,7 @@ def partition(self, var: str = '', fraction: float = .7, seed: int = 9878, kfold self.sas._lastlog = self.sas._io._log[lastlog:] elog = [] for line in ll['LOG'].splitlines(): - if line[self.sas.logoffset:].startswith('ERROR'): + if re.search(r'^ERROR[ \d-]*:', line[self.sas.logoffset:]): elog.append(line) if len(elog): raise RuntimeError("\n".join(elog)) @@ -907,7 +907,7 @@ def sort(self, by: str, out: object = '', **kwargs) -> 'SASdata': self.sas._lastlog = self.sas._io._log[lastlog:] elog = [] for line in ll['LOG'].splitlines(): - if line[self.sas.logoffset:].startswith('ERROR'): + if re.search(r'^ERROR[ \d-]*:', line[self.sas.logoffset:]): elog.append(line) if len(elog): raise RuntimeError("\n".join(elog)) @@ -1402,7 +1402,7 @@ def to_json(self, pretty: bool = False, sastag: bool = False, **kwargs) -> str: for line in ll['LOG'].splitlines(): if line[self.sas.logoffset:].startswith('JSONFilePath:'): fpath = line[14:] - if line[self.sas.logoffset:].startswith('ERROR'): + if re.search(r'^ERROR[ \d-]*:', line[self.sas.logoffset:]): elog.append(line) if len(elog): raise RuntimeError("\n".join(elog)) diff --git a/saspy/sasiocom.py b/saspy/sasiocom.py index 2b8cb159..4aad1c25 100644 --- a/saspy/sasiocom.py +++ b/saspy/sasiocom.py @@ -21,6 +21,7 @@ import shlex import sys import warnings +import re import logging logger = logging.getLogger('saspy') @@ -303,7 +304,7 @@ def _getlog(self, buf: int=2048) -> str: # Store flush result in running log self._log += result - if result.count('\nERROR:') > 0: + if re.search(r'\nERROR[ \d-]*:', result): 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 diff --git a/saspy/sasiohttp.py b/saspy/sasiohttp.py index 2c7fb0ed..801ecee4 100644 --- a/saspy/sasiohttp.py +++ b/saspy/sasiohttp.py @@ -24,6 +24,7 @@ import io import ssl import atexit +import re import secrets import hashlib @@ -977,7 +978,7 @@ def _getlog(self, jobid=None, loglines=False): logr = logr.replace(chr(12), chr(10)) self._log += logr - if logr.count('\nERROR:') > 0: + if re.search(r'\nERROR[ \d-]*:', logr): 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 diff --git a/saspy/sasioiom.py b/saspy/sasioiom.py index 859a150a..e7adfcda 100644 --- a/saspy/sasioiom.py +++ b/saspy/sasioiom.py @@ -23,6 +23,7 @@ import warnings import io import atexit +import re import logging logger = logging.getLogger('saspy') @@ -1088,7 +1089,7 @@ 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(), '') - if logd.count('\nERROR:') > 0: + 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 @@ -2047,7 +2048,7 @@ def sasdata2dataframeCSV(self, table: str, libref: str ='', dsopts: dict = None, logd = logf.decode(errors='replace') self._log += logd.replace(chr(12), chr(10)) - if logd.count('\nERROR:') > 0: + 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 @@ -2823,7 +2824,7 @@ def read(self, size=4096): logd = self.logf.decode(errors='replace') self._io._log += logd.replace(chr(12), chr(10)) - if logd.count('\nERROR:') > 0: + 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._io._sb.check_error_log = True diff --git a/saspy/sasiostdio.py b/saspy/sasiostdio.py index da70cd90..a3d6e309 100755 --- a/saspy/sasiostdio.py +++ b/saspy/sasiostdio.py @@ -616,7 +616,7 @@ def _endsas(self): def _checkLogForError(self, log): lines = re.split(r'[\n]\s*', log) for line in lines: - if line[self._sb.logoffset:].startswith('ERROR:'): + if re.search(r'^ERROR[ \d-]*:', line[self._sb.logoffset:]): return (True) return (False) diff --git a/saspy/sasproccommons.py b/saspy/sasproccommons.py index 30608d34..2eb69495 100644 --- a/saspy/sasproccommons.py +++ b/saspy/sasproccommons.py @@ -202,7 +202,7 @@ def _errorLog(self, log): for line in lines: i += 1 e = [] - if line[self.sas.logoffset:].startswith('ERROR'): + if re.search(r'^ERROR[ \d-]*:', line[self.sas.logoffset:]): e = lines[(max(i - 1, 0)):(min(i + 0, len(lines)))] elog = elog + e return "\n".join(elog)