[Frontend] Improve error message (#31987)

Signed-off-by: DarkLight1337 <tlleungac@connect.ust.hk>
This commit is contained in:
Cyrus Leung
2026-01-08 20:07:03 +00:00
committed by GitHub
parent f16bfbe5bc
commit aa125ecf0e
3 changed files with 20 additions and 4 deletions
+10
View File
@@ -0,0 +1,10 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
from vllm.entrypoints.utils import sanitize_message
def test_sanitize_message():
assert (
sanitize_message("<_io.BytesIO object at 0x7a95e299e750>")
== "<_io.BytesIO object>"
)
+4 -4
View File
@@ -88,8 +88,10 @@ from vllm.entrypoints.utils import (
log_non_default_args, log_non_default_args,
process_chat_template, process_chat_template,
process_lora_modules, process_lora_modules,
sanitize_message,
with_cancellation, with_cancellation,
) )
from vllm.exceptions import VLLMValidationError
from vllm.logger import init_logger from vllm.logger import init_logger
from vllm.reasoning import ReasoningParserManager from vllm.reasoning import ReasoningParserManager
from vllm.tasks import POOLING_TASKS from vllm.tasks import POOLING_TASKS
@@ -902,7 +904,7 @@ def build_app(args: Namespace) -> FastAPI:
async def http_exception_handler(_: Request, exc: HTTPException): async def http_exception_handler(_: Request, exc: HTTPException):
err = ErrorResponse( err = ErrorResponse(
error=ErrorInfo( error=ErrorInfo(
message=exc.detail, message=sanitize_message(exc.detail),
type=HTTPStatus(exc.status_code).phrase, type=HTTPStatus(exc.status_code).phrase,
code=exc.status_code, code=exc.status_code,
) )
@@ -911,8 +913,6 @@ def build_app(args: Namespace) -> FastAPI:
@app.exception_handler(RequestValidationError) @app.exception_handler(RequestValidationError)
async def validation_exception_handler(_: Request, exc: RequestValidationError): async def validation_exception_handler(_: Request, exc: RequestValidationError):
from vllm.exceptions import VLLMValidationError
param = None param = None
for error in exc.errors(): for error in exc.errors():
if "ctx" in error and "error" in error["ctx"]: if "ctx" in error and "error" in error["ctx"]:
@@ -931,7 +931,7 @@ def build_app(args: Namespace) -> FastAPI:
err = ErrorResponse( err = ErrorResponse(
error=ErrorInfo( error=ErrorInfo(
message=message, message=sanitize_message(message),
type=HTTPStatus.BAD_REQUEST.phrase, type=HTTPStatus.BAD_REQUEST.phrase,
code=HTTPStatus.BAD_REQUEST, code=HTTPStatus.BAD_REQUEST,
param=param, param=param,
+6
View File
@@ -9,6 +9,7 @@ from argparse import Namespace
from pathlib import Path from pathlib import Path
from typing import Any from typing import Any
import regex as re
from fastapi import Request from fastapi import Request
from fastapi.responses import JSONResponse, StreamingResponse from fastapi.responses import JSONResponse, StreamingResponse
from starlette.background import BackgroundTask, BackgroundTasks from starlette.background import BackgroundTask, BackgroundTasks
@@ -317,3 +318,8 @@ async def process_chat_template(
model_config.model, model_config.model,
) )
return resolved_chat_template return resolved_chat_template
def sanitize_message(message: str) -> str:
# Avoid leaking memory address from object reprs
return re.sub(r" at 0x[0-9a-f]+>", ">", message)