iflytek/astron-agent · error · ServiceException
ServiceLocalError
ServiceLocalError
Error message
起始页号应该小于等于结束页号
What it means
pdf_convert_png validates the requested page range before converting. If page_start > page_end and page_end is not the unlimited sentinel (DOCUMENT_PAGE_UNLIMITED) and page_start is also not unlimited, it raises ServiceLocalError saying the start page must be <= end page.
Solutions
- Ensure page_start <= page_end (or set page_end to DOCUMENT_PAGE_UNLIMITED for open-ended ranges)
- Check argument order at the call site (start, end)
- Use DOCUMENT_PAGE_UNLIMITED for unbounded ranges instead of 0/-1/None
- Validate the range from user input before invoking
Example fix
// before
pdf_convert_png(pdf_bytes, page_start=5, page_end=2)
// after
if page_start > page_end:
page_start, page_end = page_end, page_start
pdf_convert_png(pdf_bytes, page_start=page_start, page_end=page_end) Defensive patterns
Strategy: validation
Validate before calling
if page_start > page_end != DOCUMENT_PAGE_UNLIMITED and page_start != DOCUMENT_PAGE_UNLIMITED:
page_start, page_end = min(page_start, page_end), max(page_start, page_end) Try / catch
try:
pngs, texts = pdf_convert_png(pdf_bytes, page_start, page_end)
except ServiceException as e:
if e.code == CodeEnums.ServiceLocalError.code:
log.error('bad page range: %s', e.message)
pngs, texts = pdf_convert_png(pdf_bytes, DOCUMENT_PAGE_UNLIMITED, DOCUMENT_PAGE_UNLIMITED) Prevention
- Sanitize/swap user-supplied page ranges before calling
- Use DOCUMENT_PAGE_UNLIMITED for open-ended ranges, not 0 or -1
- Add a regression test for swapped start/end arguments
When it happens
Trigger: Calling pdf_convert_png with e.g. page_start=5, page_end=2, or page_start=3, page_end=0 when both are concrete numbers.
Common situations: Swapped arguments at the call site; computing page indices from UI 1-based vs 0-based values; defaulting page_end to 0 instead of the unlimited sentinel.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12).
Data as JSON: /api/errors/cea64c095f21daa4.
Report an issue: GitHub.
Appendix: source
Thrown at core/plugin/aitools/service/ocr_llm/req_ase_ability_ocr_service.py:432
page_start: int = DOCUMENT_PAGE_UNLIMITED,
page_end: int = DOCUMENT_PAGE_UNLIMITED,
) -> Tuple[Dict[int, bytes], Dict[int, str]]:
"""
PDF convert to PNG.
Args:
pdf_content: PDF content in bytes.
page_start: Start page number. -1 means all pages.
page_end: End page number. -1 means all pages.
Returns:
A tuple of two dictionaries. The first dictionary contains the page number as key and the corresponding PNG image in bytes as value. The second dictionary contains the page number as key and the corresponding text in the page as value.
"""
if (
page_start > page_end != DOCUMENT_PAGE_UNLIMITED
and page_start != DOCUMENT_PAGE_UNLIMITED
):
raise ServiceException.from_error_code(
CodeEnums.ServiceLocalError, extra_message="起始页号应该小于等于结束页号"
)
if not pdf_content.startswith(b"%PDF-"):
raise ServiceException.from_error_code(
CodeEnums.ServiceLocalError, extra_message="PDF 内容格式错误"
)
pngs = {}
texts = {}
with fitz.Document(stream=pdf_content, filetype="pdf") as pdf:
for i, page in enumerate(pdf):
if page_start != DOCUMENT_PAGE_UNLIMITED and i < page_start:
continue
if page_end != DOCUMENT_PAGE_UNLIMITED and i > page_end:
break
# rotate = int(0)
# Each size zoom factor is 2, which will generate an image with a resolution of 4.View on GitHub (pinned to 5e758547a8)