Skip to content

Commit

Permalink
Add GenAi-PA error handling (#483)
Browse files Browse the repository at this point in the history
* Print exception when non-zero error code

* Add test for GenAiPAException for nonzero exit

* Revert format/comment changes.

* Fix typo

Co-authored-by: Ryan McCormick <rmccormick@nvidia.com>

* Remove unnecessary return value

Co-authored-by: Ryan McCormick <rmccormick@nvidia.com>

---------

Co-authored-by: Ryan McCormick <rmccormick@nvidia.com>
  • Loading branch information
2 people authored and debermudez committed Mar 13, 2024
1 parent 33831b0 commit 14c1283
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from typing import Dict, List, Optional, Tuple

import requests
from genaipa_exceptions import GenAiPAException
from genai_pa.exceptions import GenAiPAException
from requests import Response


Expand Down
8 changes: 6 additions & 2 deletions src/c++/perf_analyzer/genai-pa/genai_pa/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

from genai_pa import parser
from genai_pa.constants import LOGGER_NAME
from genai_pa.exceptions import GenAiPAException

logging.basicConfig(level=logging.INFO, format="%(name)s - %(levelname)s - %(message)s")
logger = logging.getLogger(LOGGER_NAME)
Expand All @@ -39,8 +40,11 @@
# to assert correct errors and messages.
# Optional argv used for testing - will default to sys.argv if None.
def run(argv=None):
args = parser.parse_args(argv)
args.func(args)
try:
args = parser.parse_args(argv)
args.func(args)
except Exception as e:
raise GenAiPAException(e)


def main():
Expand Down
2 changes: 1 addition & 1 deletion src/c++/perf_analyzer/genai-pa/genai_pa/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ def run(model, args=None):
arg = utils.convert_option_name(arg)
cmd += f"--{arg} {value} "
logger.info(f"Running Perf Analyzer : '{cmd}'")
subprocess.run(cmd, shell=True)
subprocess.run(cmd, shell=True, check=True)
6 changes: 6 additions & 0 deletions src/c++/perf_analyzer/genai-pa/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

import pytest
from genai_pa import parser
from genai_pa.exceptions import GenAiPAException
from genai_pa.main import run


class TestCLIArguments:
Expand Down Expand Up @@ -91,3 +93,7 @@ def test_arguments_model_not_provided(self):

# Check that the exit was unsuccessful
assert exc_info.value.code != 0

def test_exception_on_nonzero_exit(self):
with pytest.raises(GenAiPAException) as e:
run(["-m", "nonexistent_model"])
4 changes: 2 additions & 2 deletions src/c++/perf_analyzer/genai-pa/tests/test_llm_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import os

import pytest
from genaipa_exceptions import GenAiPAException
from llm_inputs.llm_inputs import LlmInputs
from genai_pa.exceptions import GenAiPAException
from genai_pa.llm_inputs.llm_inputs import LlmInputs


class TestLlmInputs:
Expand Down

0 comments on commit 14c1283

Please sign in to comment.