[Frontend] Consolidate entrypoint exception handler (#52261)
Signed-off-by: wang.yuqi <yuqi.wang@daocloud.io>
This commit is contained in:
@@ -44,7 +44,9 @@ from vllm.entrypoints.openai.engine.protocol import (
|
||||
PromptTokenUsageInfo,
|
||||
UsageInfo,
|
||||
)
|
||||
from vllm.entrypoints.serve.utils.server_utils import validation_exception_handler
|
||||
from vllm.entrypoints.serve.exception_handling.handlers.validation import (
|
||||
validation_exception_handler,
|
||||
)
|
||||
|
||||
_convert = AnthropicServingMessages._convert_anthropic_to_openai_request
|
||||
_img_url = AnthropicServingMessages._convert_image_source_to_url
|
||||
|
||||
@@ -30,8 +30,10 @@ from vllm.entrypoints.cohere.protocol import (
|
||||
CohereChatV2Response,
|
||||
)
|
||||
from vllm.entrypoints.openai.engine.protocol import ErrorInfo, ErrorResponse
|
||||
from vllm.entrypoints.serve.utils.server_utils import (
|
||||
from vllm.entrypoints.serve.exception_handling.handlers.http import (
|
||||
http_exception_handler,
|
||||
)
|
||||
from vllm.entrypoints.serve.exception_handling.handlers.validation import (
|
||||
validation_exception_handler,
|
||||
)
|
||||
|
||||
|
||||
+54
-1
@@ -10,7 +10,60 @@ speech-to-text WebSocket paths.
|
||||
|
||||
import pytest
|
||||
|
||||
from vllm.entrypoints.serve.utils.api_utils import sanitize_message
|
||||
from vllm.entrypoints.serve.exception_handling.utils import sanitize_message
|
||||
|
||||
|
||||
def test_sanitize_message():
|
||||
assert (
|
||||
sanitize_message("<_io.BytesIO object at 0x7a95e299e750>")
|
||||
== "<_io.BytesIO object>"
|
||||
)
|
||||
|
||||
|
||||
class TestSanitizeMessageFilePaths:
|
||||
"""sanitize_message should also strip file paths and traceback
|
||||
frames, not just memory addresses - see #31683."""
|
||||
|
||||
def test_strips_traceback_style_frame(self):
|
||||
msg = (
|
||||
"1 validation error:\n"
|
||||
" {'type': 'list_type', 'loc': ('body', 'messages')}\n"
|
||||
'\n File "/usr/local/lib/python3.12/dist-packages/vllm/'
|
||||
'entrypoints/serve/utils/api_utils.py", line 40, '
|
||||
"in create_chat_completion\n"
|
||||
" POST /v1/chat/completions"
|
||||
)
|
||||
result = sanitize_message(msg)
|
||||
assert "/usr/local/" not in result
|
||||
assert "api_utils.py" not in result
|
||||
assert "list_type" in result
|
||||
|
||||
def test_strips_arbitrary_absolute_path(self):
|
||||
result = sanitize_message("Error in /home/user/project/vllm/server.py")
|
||||
assert "/home/user" not in result
|
||||
|
||||
def test_strips_single_parent_container_path(self):
|
||||
"""Regression: /app/server.py and /workspace/server.py (common in
|
||||
container deployments) were missed by the original {2,} quantifier."""
|
||||
assert "/app/" not in sanitize_message("Error in /app/server.py")
|
||||
assert "/workspace/" not in sanitize_message("Error in /workspace/server.py")
|
||||
|
||||
def test_preserves_api_endpoint_paths(self):
|
||||
msg = "POST /v1/chat/completions failed"
|
||||
assert "/v1/chat/completions" in sanitize_message(msg)
|
||||
|
||||
def test_preserves_short_field_references(self):
|
||||
msg = "Invalid value for field 'body.messages'"
|
||||
assert sanitize_message(msg) == msg
|
||||
|
||||
def test_strips_both_address_and_path(self):
|
||||
msg = (
|
||||
"<Request at 0x7f123> failed at "
|
||||
"/usr/local/lib/python3.12/dist-packages/vllm/server.py"
|
||||
)
|
||||
result = sanitize_message(msg)
|
||||
assert "0x" not in result
|
||||
assert "/usr/local/" not in result
|
||||
|
||||
|
||||
class TestSanitizeMessageCoversLeakPatterns:
|
||||
+1
-1
@@ -16,7 +16,7 @@ from types import SimpleNamespace
|
||||
import pytest
|
||||
from fastapi.exceptions import RequestValidationError
|
||||
|
||||
from vllm.entrypoints.serve.utils.server_utils import (
|
||||
from vllm.entrypoints.serve.exception_handling.handlers.validation import (
|
||||
clean_loc_for_param,
|
||||
validation_exception_handler,
|
||||
)
|
||||
@@ -6,18 +6,10 @@ import pytest
|
||||
from vllm.entrypoints.openai.engine.protocol import StreamOptions
|
||||
from vllm.entrypoints.serve.utils.api_utils import (
|
||||
get_max_tokens,
|
||||
sanitize_message,
|
||||
should_include_usage,
|
||||
)
|
||||
|
||||
|
||||
def test_sanitize_message():
|
||||
assert (
|
||||
sanitize_message("<_io.BytesIO object at 0x7a95e299e750>")
|
||||
== "<_io.BytesIO object>"
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("stream_options", "expected"),
|
||||
[
|
||||
@@ -118,49 +110,3 @@ class TestGetMaxTokens:
|
||||
input_length=150,
|
||||
default_sampling_params={"max_tokens": 2048},
|
||||
)
|
||||
|
||||
|
||||
class TestSanitizeMessageFilePaths:
|
||||
"""sanitize_message should also strip file paths and traceback
|
||||
frames, not just memory addresses - see #31683."""
|
||||
|
||||
def test_strips_traceback_style_frame(self):
|
||||
msg = (
|
||||
"1 validation error:\n"
|
||||
" {'type': 'list_type', 'loc': ('body', 'messages')}\n"
|
||||
'\n File "/usr/local/lib/python3.12/dist-packages/vllm/'
|
||||
'entrypoints/serve/utils/api_utils.py", line 40, '
|
||||
"in create_chat_completion\n"
|
||||
" POST /v1/chat/completions"
|
||||
)
|
||||
result = sanitize_message(msg)
|
||||
assert "/usr/local/" not in result
|
||||
assert "api_utils.py" not in result
|
||||
assert "list_type" in result
|
||||
|
||||
def test_strips_arbitrary_absolute_path(self):
|
||||
result = sanitize_message("Error in /home/user/project/vllm/server.py")
|
||||
assert "/home/user" not in result
|
||||
|
||||
def test_strips_single_parent_container_path(self):
|
||||
"""Regression: /app/server.py and /workspace/server.py (common in
|
||||
container deployments) were missed by the original {2,} quantifier."""
|
||||
assert "/app/" not in sanitize_message("Error in /app/server.py")
|
||||
assert "/workspace/" not in sanitize_message("Error in /workspace/server.py")
|
||||
|
||||
def test_preserves_api_endpoint_paths(self):
|
||||
msg = "POST /v1/chat/completions failed"
|
||||
assert "/v1/chat/completions" in sanitize_message(msg)
|
||||
|
||||
def test_preserves_short_field_references(self):
|
||||
msg = "Invalid value for field 'body.messages'"
|
||||
assert sanitize_message(msg) == msg
|
||||
|
||||
def test_strips_both_address_and_path(self):
|
||||
msg = (
|
||||
"<Request at 0x7f123> failed at "
|
||||
"/usr/local/lib/python3.12/dist-packages/vllm/server.py"
|
||||
)
|
||||
result = sanitize_message(msg)
|
||||
assert "0x" not in result
|
||||
assert "/usr/local/" not in result
|
||||
|
||||
Reference in New Issue
Block a user