Interpolates an error message. The error message can contain tags of the form `{{type name}}` which will be replaced. For example: "{{node }}" would get expanded to: "node (defined at )". Args: error_message: A string to interpolate. graph: ops.Graph object contai
(error_message, graph)
| 422 | |
| 423 | |
| 424 | def interpolate(error_message, graph): |
| 425 | """Interpolates an error message. |
| 426 | |
| 427 | The error message can contain tags of the form `{{type name}}` which will be |
| 428 | replaced. For example: "{{node <name>}}" would get expanded to: |
| 429 | "node <name>(defined at <path>)". |
| 430 | |
| 431 | Args: |
| 432 | error_message: A string to interpolate. |
| 433 | graph: ops.Graph object containing all nodes referenced in the error |
| 434 | message. |
| 435 | |
| 436 | Returns: |
| 437 | The string with tags of the form {{type name}} interpolated. |
| 438 | """ |
| 439 | seps, tags = parse_message(error_message) |
| 440 | subs = [] |
| 441 | end_msg = collections.defaultdict(list) |
| 442 | tagged_ops = [] |
| 443 | |
| 444 | for t in tags: |
| 445 | try: |
| 446 | op = graph.get_operation_by_name(t.name) |
| 447 | except KeyError: |
| 448 | op = None |
| 449 | if op is None: |
| 450 | tagged_ops.append(None) |
| 451 | else: |
| 452 | tagged_ops.append([op] + _sources_for_node(op, graph)) |
| 453 | |
| 454 | common_prefix = traceback_files_common_prefix(tagged_ops) |
| 455 | for tag, ops in zip(tags, tagged_ops): |
| 456 | msg = "{{%s %s}}" % (tag.type, tag.name) |
| 457 | if ops is not None: |
| 458 | if tag.type == "node": |
| 459 | msg, source_msg = _build_error_message(ops[0], ops[1:], common_prefix) |
| 460 | if source_msg: |
| 461 | end_msg["source_nodes"].append(source_msg) |
| 462 | elif tag.type == "colocation_node": |
| 463 | field_dict = compute_field_dict(ops[0], common_prefix) |
| 464 | msg = "node %s%s placed on device %s " % ( |
| 465 | ops[0].name, field_dict["defined_at"], field_dict["devices"]) |
| 466 | end_msg["colocations"].append(field_dict["devs_and_colocs"]) |
| 467 | if tag.type == "function_node": |
| 468 | msg = "" |
| 469 | subs.append(msg) |
| 470 | |
| 471 | if "source_nodes" in end_msg: |
| 472 | subs.append("\n\nErrors may have originated from an input operation.") |
| 473 | subs.append("\n".join(end_msg["source_nodes"])) |
| 474 | end_msg.pop("source_nodes", None) |
| 475 | for k, messages in end_msg.items(): |
| 476 | subs.append("Additional information about %s:" % k) |
| 477 | subs.append("\n".join(messages)) |
| 478 | |
| 479 | return "".join( |
| 480 | itertools.chain(*six.moves.zip_longest(seps, subs, fillvalue=""))) |
nothing calls this directly
no test coverage detected