Skip to content

Commit

Permalink
fix issue 615
Browse files Browse the repository at this point in the history
  • Loading branch information
tomweber-sas committed Sep 6, 2024
1 parent 3061e5a commit 3d96263
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 15 deletions.
6 changes: 3 additions & 3 deletions saspy/sas_magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def SAS(self, line, cell):
set sashelp.cars;
run;
"""

mva = self.mva
if len(line): # session supplied
names = line.split('.')
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion saspy/sasbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=');
Expand Down
8 changes: 4 additions & 4 deletions saspy/sasdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, '')

Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down
3 changes: 2 additions & 1 deletion saspy/sasiocom.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import shlex
import sys
import warnings
import re

import logging
logger = logging.getLogger('saspy')
Expand Down Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion saspy/sasiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import io
import ssl
import atexit
import re

import secrets
import hashlib
Expand Down Expand Up @@ -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

Expand Down
7 changes: 4 additions & 3 deletions saspy/sasioiom.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import warnings
import io
import atexit
import re

import logging
logger = logging.getLogger('saspy')
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion saspy/sasiostdio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion saspy/sasproccommons.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3d96263

Please sign in to comment.