From 37c84617b1036c6fe56c40ea369dcb58f6ec2921 Mon Sep 17 00:00:00 2001 From: Adam Wilson Date: Thu, 24 Apr 2025 11:44:46 -0600 Subject: [PATCH] error handling - take 2 --- .github/workflows/llmsecops-cicd.yml | 10 +++++----- tests/api/controller.py | 17 +++++++++++++---- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/.github/workflows/llmsecops-cicd.yml b/.github/workflows/llmsecops-cicd.yml index d6a27c867..93caa8d8e 100644 --- a/.github/workflows/llmsecops-cicd.yml +++ b/.github/workflows/llmsecops-cicd.yml @@ -37,8 +37,8 @@ jobs: - name: Run REST API server run: | # python ${{ github.workspace }}/tests/api/server.py & - python -m tests.api.server & - - - name: Test API call - run: | - curl -X POST -i localhost:9999 -d '{ "prompt": "describe a random planet in our solar system in 10 words or less" }' \ No newline at end of file + nohup python -m tests.api.server > server.log 2>&1 & + sleep 2 + curl -X POST -i localhost:9999 -d '{ "prompt": "describe a random planet in our solar system in 10 words or less" }' || true + echo "--- SERVER LOG ---" + cat server.log \ No newline at end of file diff --git a/tests/api/controller.py b/tests/api/controller.py index 00d43a766..60343085f 100644 --- a/tests/api/controller.py +++ b/tests/api/controller.py @@ -1,4 +1,5 @@ import json +import traceback from tests.llm.phi3_language_model import Phi3LanguageModel @@ -53,7 +54,15 @@ class ApiController: start_response('400 Bad Request', response_headers) return [response_body] except Exception as e: - response_body = e.msg.encode('utf-8') - response_headers = [('Content-Type', 'text/plain'), ('Content-Length', str(len(response_body)))] - start_response('500 Internal Server Error', response_headers) - return [response_body] + # response_body = e.msg.encode('utf-8') + # response_headers = [('Content-Type', 'text/plain'), ('Content-Length', str(len(response_body)))] + # start_response('500 Internal Server Error', response_headers) + # return [response_body] + + # Log to stdout so it shows in GitHub Actions + print("Exception occurred:") + traceback.print_exc() + + # Return more detailed error response + start_response('500 Internal Server Error', [('Content-Type', 'text/plain')]) + return [f"Internal Server Error:\n{e}\n".encode()]