Skip to content

Commit c2cf5ba

Browse files
committed
opt: on error message
1 parent fe7760e commit c2cf5ba

File tree

2 files changed

+27
-22
lines changed

2 files changed

+27
-22
lines changed

absbox/client.py

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,17 @@ def buildPoolType(p) -> dict:
294294

295295
return json.dumps(r, ensure_ascii=False)
296296

297+
@staticmethod
298+
def _getWarningMsg(msgs, flag:bool) -> []:
299+
"""get warning message from server response
300+
:return: list of warning messages
301+
:rtype: list
302+
"""
303+
if flag:
304+
return [f"{x['contents']}" for x in filter_by_tags(msgs, enumVals(ValidationMsg))]
305+
else:
306+
return []
307+
297308
def run(self, deal,
298309
poolAssump=None,
299310
runAssump=[],
@@ -337,9 +348,9 @@ def run(self, deal,
337348
leftVal = result.get("Left","")
338349
raise AbsboxError(f"❌ Failed to get response from run: {leftVal}")
339350
result = result['Right']
340-
rawWarnMsg = map(lambda x:f" {x['contents']}", filter_by_tags(result[RunResp.LogResp.value], enumVals(ValidationMsg)))
341-
if rawWarnMsg and showWarning:
342-
console.print("Warning Message from server:\n"+"\n".join(list(rawWarnMsg)))
351+
352+
if (wMsgs:=self._getWarningMsg(result[RunResp.LogResp.value], showWarning)):
353+
console.print("Warning Message from server:"+"\n".join(wMsgs))
343354

344355
if read:
345356
return deal.read(result)
@@ -387,11 +398,10 @@ def runByScenarios(self, deal,
387398

388399
result = tz.valmap(lambda x:x['Right'] ,result)
389400

390-
rawWarnMsgByScen = {k: [f" {_['contents']}" for _ in filter_by_tags(v[RunResp.LogResp.value], enumVals(ValidationMsg))] for k, v in result.items()}
391-
rawWarnMsg = list(tz.concat(rawWarnMsgByScen.values()))
392-
393-
if showWarning and len(rawWarnMsg)>0:
394-
console.print("Warning Message from server:\n"+"\n".join(rawWarnMsg))
401+
rawWarnMsgByScen = {k: _getWarningMsg(v[RunResp.LogResp.value],showWarning) for k, v in result.items()}
402+
for scen, msgs in rawWarnMsgByScen.items():
403+
if len(msgs)>0:
404+
console.print(f"Warning Message from server for {scen}:"+"\n".join(msgs))
395405

396406
if read:
397407
return tz.valmap(deal.read, result)
@@ -566,11 +576,10 @@ def runByDealScenarios(self, deal,
566576

567577
result = tz.valmap(lambda x:x['Right'] ,result)
568578

569-
rawWarnMsgByScen = {k: [f" {_['contents']}" for _ in filter_by_tags(v[RunResp.LogResp.value], enumVals(ValidationMsg))] for k, v in result.items()}
570-
rawWarnMsg = list(tz.concat(rawWarnMsgByScen.values()))
571-
572-
if showWarning and len(rawWarnMsg)>0:
573-
console.print("Warning Message from server:\n"+"\n".join(rawWarnMsg))
579+
rawWarnMsgByScen = {k: _getWarningMsg(v[RunResp.LogResp.value],showWarning) for k, v in result.items()}
580+
for scen, msgs in rawWarnMsgByScen.items():
581+
if len(msgs)>0:
582+
console.print(f"Warning Message from server for {scen}:"+"\n".join(msgs))
574583

575584
if read:
576585
return tz.valmap(deal.read, result)
@@ -621,14 +630,10 @@ def runByCombo(self,
621630

622631
assert isinstance(result, dict), f"Result should be a dict but got {type(result)}, {result}"
623632

624-
rawWarnMsgByScen = {"^".join(k): [f" {_['contents']}"
625-
for _ in filter_by_tags(v[RunResp.LogResp.value], enumVals(ValidationMsg))]
626-
for k, v in result.items()}
627-
628-
rawWarnMsg = list(tz.concat(rawWarnMsgByScen.values()))
629-
630-
if showWarning and len(rawWarnMsg)>0:
631-
console.print("Warning Message from server:\n"+"\n".join(rawWarnMsg))
633+
rawWarnMsgByScen = {"^".join(k): _getWarningMsg(v[RunResp.LogResp.value],showWarning) for k, v in result.items()}
634+
for scen, msgs in rawWarnMsgByScen.items():
635+
if len(msgs)>0:
636+
console.print(f"Warning Message from server for {scen}:"+"\n".join(msgs))
632637

633638
if read:
634639
return {

docs/source/library.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ User can initiate a run request sending to server. The server will find ``Hastru
105105

106106
<Run Type>
107107
Can be either :
108-
* "S" -> Default,single run
108+
* "S" -> Default,single run (Default)
109109
* "MC" -> Multiple pool assumption
110110
* "MRS" -> Multiple run assumption
111111
* "CS" -> Combo (multiple pool and run assumption)

0 commit comments

Comments
 (0)