Skip to content

Commit

Permalink
Process 'warning' in return: #1336
Browse files Browse the repository at this point in the history
  • Loading branch information
gfursin committed Oct 21, 2024
1 parent 11dd1e9 commit 720c81c
Showing 1 changed file with 40 additions and 29 deletions.
69 changes: 40 additions & 29 deletions cm/cmind/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ def error(self, r):
if self.debug:
raise Exception(r['error'])

sys.stderr.write('\n'+self.cfg['error_prefix']+' '+r['error']+'!\n')
text = self.cfg['error_prefix'] + ' ' + r['error'] + '!\n'

sys.stderr.write(f'\n{text}')

return r

Expand All @@ -159,39 +161,44 @@ def errorx(self, r):
if self.debug:
raise Exception(r['error'])

module_path = r.get('module_path', '')
lineno = r.get('lineno', '')
if 'warning' in r:
message = r.get('warning', '')
if message != '':
message = '\nCMX warning: ' + message.capitalize() + '!\n'
else:
module_path = r.get('module_path', '')
lineno = r.get('lineno', '')

message = ''
message = ''

if not self.logger == None or (module_path != '' and lineno != ''):
call_stack = self.state.get('call_stack', [])
if not self.logger == None or (module_path != '' and lineno != ''):
call_stack = self.state.get('call_stack', [])

if not self.logger == None:
if not self.logger == None:

self.log(f"x error call stack: {call_stack}", "debug")
self.log(f"x error: {r}", "debug")
self.log(f"x error call stack: {call_stack}", "debug")
self.log(f"x error: {r}", "debug")

sys.stderr.write('='*60 + '\n')
sys.stderr.write('^'*60 + '\n')

if not self.logger == None:
sys.stderr.write('CMX call stack:\n')
if not self.logger == None:
sys.stderr.write('CMX call stack:\n')

for cs in call_stack:
sys.stderr.write(f' * {cs}\n')
for cs in call_stack:
sys.stderr.write(f' * {cs}\n')

message += '\n'
else:
message += '\n'
else:
message += '\n'

message += self.cfg['error_prefix2']
message += self.cfg['error_prefix2']

if module_path != '' and lineno !='':
message += f' in {module_path} ({lineno}):\n\n'
else:
message += ': '
if module_path != '' and lineno !='':
message += f' in {module_path} ({lineno}):\n\n'
else:
message += ': '

message += r['error'] + '\n'
message += r['error'] + '\n'

sys.stderr.write(message)

Expand Down Expand Up @@ -1097,7 +1104,7 @@ def _x(self, i, control):
print ('')
print ('Check https://github.com/mlcommons/ck/tree/master/cm/docs/cmx for more details.')

return {'return':0, 'warning':'no action specified'}
return {'return':1, 'warning':'', 'error':'help requested'}

# Load info about all CM repositories (to enable search for automations and artifacts)
if self.repos == None:
Expand Down Expand Up @@ -1292,11 +1299,13 @@ def _x(self, i, control):

# Check if common automation and --help
if (use_common_automation or automation == '') and cm_help:
return print_action_help(self.common_automation,
self.common_automation,
'common',
action,
original_action)
r = print_action_help(self.common_automation,
self.common_automation,
'common',
action,
original_action)

return {'return':1, 'warning':'', 'error':'help requested'}

# If no automation was found we do not force common automation, check if should fail or continue
if not use_common_automation and len(automation_lst)==0:
Expand Down Expand Up @@ -1371,7 +1380,7 @@ def _x(self, i, control):
for d in actions:
print (' * cmx ' + d + ' ' + automation_meta.get('alias','') + ' -h')

return {'return':0, 'warning':'no automation action'}
return {'return':1, 'warning':'', 'error':'help requested'}


if not hasattr(initialized_automation, action):
Expand Down Expand Up @@ -1488,6 +1497,8 @@ def _x(self, i, control):
print ('')
print (delayed_help_api)

return {'return':1, 'warning':'', 'error':'help requested'}

return r


Expand Down

0 comments on commit 720c81c

Please sign in to comment.