|
2 | 2 | import logging
|
3 | 3 | import os
|
4 | 4 | import re
|
| 5 | +import sys |
5 | 6 |
|
6 | 7 | try:
|
7 | 8 | # py 311 adds this library natively
|
|
28 | 29 | from jinja2 import Environment, FileSystemLoader
|
29 | 30 |
|
30 | 31 |
|
| 32 | +logging.basicConfig( |
| 33 | + stream=sys.stdout, |
| 34 | + format="[%(levelname)s] %(message)s", |
| 35 | +) |
31 | 36 | _LOGGER = logging.getLogger(__name__)
|
32 | 37 | _SDK_FOLDER_RE = re.compile(r"^(sdk/[\w-]+)/(azure[\w-]+)/", re.ASCII)
|
33 | 38 |
|
@@ -539,21 +544,28 @@ def gen_typespec(
|
539 | 544 | _LOGGER.info(f"generation cmd: {cmd}")
|
540 | 545 | output = check_output(cmd, stderr=STDOUT, shell=True)
|
541 | 546 | except CalledProcessError as e:
|
542 |
| - _LOGGER.error("Error occurred when call tsp-client:") |
543 |
| - for item in e.output.decode("utf-8").split("\n"): |
544 |
| - if "Error: " in item: |
545 |
| - _LOGGER.error(item) |
546 |
| - _LOGGER.info(f"whole output when fail to call tsp-client: {e.output.decode('utf-8')}") |
547 |
| - raise e |
| 547 | + output = e.output.decode("utf-8") |
| 548 | + output_lines = output.split("\n") |
| 549 | + try: |
| 550 | + start_idx = [i for i, line in enumerate(output_lines) if "error stack start" in line][0] |
| 551 | + end_idx = [i for i, line in enumerate(output_lines) if "error stack end" in line][0] |
| 552 | + error_position = "python codegen" |
| 553 | + except: |
| 554 | + start_idx = -1 |
| 555 | + end_idx = -1 |
| 556 | + error_position = "tsp compiler" |
548 | 557 |
|
549 |
| - decode_output = output.decode("utf-8") |
550 |
| - # before https://github.com/Azure/azure-sdk-tools/issues/8815, have to check output to judge whether sdk generation succeeds |
551 |
| - if " - error " in decode_output: |
552 |
| - _LOGGER.error(f"Failed to generate sdk from typespec:") |
553 |
| - for item in decode_output.split("\n"): |
554 |
| - if " - error " in item: |
| 558 | + _LOGGER.error(f"====== Error occurred in {error_position} (error stack start) ======") |
| 559 | + if start_idx != -1 and end_idx != -1: |
| 560 | + for item in output_lines[start_idx + 1 : end_idx]: |
555 | 561 | _LOGGER.error(item)
|
556 |
| - raise Exception(f"Complete output when fail to generate sdk from typespec: {decode_output}") |
| 562 | + else: |
| 563 | + for item in output_lines: |
| 564 | + if "- error " in item: |
| 565 | + _LOGGER.error(item) |
| 566 | + _LOGGER.error(f"====== Error occurred in {error_position} (error stack end) ======") |
| 567 | + |
| 568 | + raise e |
557 | 569 |
|
558 | 570 | with open(Path("eng/emitter-package.json"), "r") as file_in:
|
559 | 571 | data = json.load(file_in)
|
|
0 commit comments