Skip to content

Commit

Permalink
Log warnings for failures and preemptions.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 610375461
Change-Id: I834ca62e6b4fd7161ea4a6f1a66820259bdd0762
  • Loading branch information
Default authored and copybara-github committed Feb 26, 2024
1 parent 222e6bb commit e5ffb44
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions py/agentflow/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@
}


def log_warning(string, color=None):
if color is None or not sys.stderr.isatty():
logging.warning(string)
else:
logging.warning('%s%s%s', ANSI_COLORS[color], string, ANSI_COLORS['end'])


def log_info(string, color=None):
if color is None or not sys.stderr.isatty():
logging.info(string)
Expand All @@ -48,22 +55,23 @@ def log_termination_reason(cur_option: core.Option,
text = 'Option \"{}\" successful. {}'.format(cur_option.name,
option_result.termination_text)
color = option_result.termination_color or 'green'
log_info(text, color)

elif termination_reason == core.TerminationType.FAILURE:
text = 'Option \"{}\" failed. {}'.format(cur_option.name,
option_result.termination_text)
color = option_result.termination_color or 'red'
log_warning(text, color)

elif termination_reason == core.TerminationType.PREEMPTED:
text = 'Option \"{}\" preempted. {}'.format(cur_option.name,
option_result.termination_text)
color = option_result.termination_color or 'yellow'
log_warning(text, color)

else:
raise ValueError('Unknown exit code from subtask.')

log_info(text, color)


if hasattr(contextlib, 'nullcontext'):
nullcontext = contextlib.nullcontext # pylint: disable=invalid-name
Expand Down

0 comments on commit e5ffb44

Please sign in to comment.