MCPcopy Index your code
hub / github.com/google/python-fire / _DisplayError

Function _DisplayError

fire/core.py:278–302  ·  view source on GitHub ↗

Prints the Fire trace and the error to stdout.

(component_trace)

Source from the content-addressed store, hash-verified

276
277
278def _DisplayError(component_trace):
279 """Prints the Fire trace and the error to stdout."""
280 result = component_trace.GetResult()
281
282 output = []
283 show_help = False
284 for help_flag in ('-h', '--help'):
285 if help_flag in component_trace.elements[-1].args:
286 show_help = True
287
288 if show_help:
289 command = f'{component_trace.GetCommand()} -- --help'
290 print(f'INFO: Showing help with the command {shlex.quote(command)}.\n',
291 file=sys.stderr)
292 help_text = helptext.HelpText(result, trace=component_trace,
293 verbose=component_trace.verbose)
294 output.append(help_text)
295 Display(output, out=sys.stderr)
296 else:
297 print(formatting.Error('ERROR: ')
298 + component_trace.elements[-1].ErrorAsStr(),
299 file=sys.stderr)
300 error_text = helptext.UsageText(result, trace=component_trace,
301 verbose=component_trace.verbose)
302 print(error_text, file=sys.stderr)
303
304
305def _DictAsString(result, verbose=False):

Callers 1

FireFunction · 0.85

Calls 4

DisplayFunction · 0.85
GetResultMethod · 0.80
GetCommandMethod · 0.80
ErrorAsStrMethod · 0.80

Tested by

no test coverage detected