{"record":{"id":"99f5784c674a72bf","repo":"ZhuLinsen/daily_stock_analysis","slug":"max-text-bytes-1024-kb","errorCode":null,"errorMessage":"文本超过 {MAX_TEXT_BYTES // 1024}KB 限制","messagePattern":"文本超过 (.+?)KB 限制","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/services/import_parser.py","lineNumber":248,"sourceCode":"            rows.append(parts)\n    if not rows:\n        return []\n    df = pd.DataFrame(rows)\n    return _parse_dataframe(df)\n\n\ndef parse_import_from_text(text: str) -> List[Tuple[Optional[str], Optional[str], str]]:\n    \"\"\"\n    Parse clipboard/text into items.\n\n    Args:\n        text: Raw text (e.g. from clipboard).\n\n    Returns:\n        List of (code, name, confidence).\n    \"\"\"\n    if len(text.encode(\"utf-8\")) > MAX_TEXT_BYTES:\n        raise ValueError(f\"文本超过 {MAX_TEXT_BYTES // 1024}KB 限制\")\n\n    logger.debug(f\"[ImportParser] 开始解析粘贴文本: bytes={len(text.encode('utf-8'))}\")\n    data = text.encode(\"utf-8\")\n    return parse_import_from_bytes(data, filename=\"paste.txt\")\n","sourceCodeStart":230,"sourceCodeEnd":253,"githubUrl":"https://github.com/ZhuLinsen/daily_stock_analysis/blob/5159bd72e8373d215492dff122acc9d389e219c9/src/services/import_parser.py#L230-L253","documentation":"Guard in parse_import_from_text: the UTF-8 byte length of the pasted text exceeds MAX_TEXT_BYTES (100KB). Measured on encoded bytes, not characters, so CJK-heavy text hits it sooner per character.","triggerScenarios":"Pasting a huge clipboard (entire watchlist page, thousands of rows with names) into the text-import UI.","commonSituations":"Select-all paste from a large spreadsheet; pasting an entire webpage rather than the code column; clipboard containing a whole CSV file.","solutions":["Paste only the code (and optionally name) column","Split the paste into batches under 100KB each","If the content is really a file, use the file upload path (2MB limit) instead"],"exampleFix":"# before\nitems = parse_import_from_text(huge_clipboard_text)\n# after\nlines = [ln for ln in huge_clipboard_text.splitlines() if ln.strip()]\nitems = []\nfor i in range(0, len(lines), 500):\n    items += parse_import_from_text('\\n'.join(lines[i:i+500]))","handlingStrategy":"validation","validationCode":"from src.services.import_parser import MAX_TEXT_BYTES\nif len(text.encode('utf-8')) > MAX_TEXT_BYTES:\n    text = '\\n'.join(ln for ln in text.splitlines() if ln.strip() and looks_like_code_or_name(ln))","typeGuard":"def within_text_limit(t: str) -> bool:\n    return len(t.encode('utf-8')) <= 100 * 1024","tryCatchPattern":null,"preventionTips":["Strip to the code/name column before pasting","Split large pastes into sub-100KB batches","Prefer file upload for very large lists (2MB allowance)"],"tags":["import","text","size-limit","clipboard"],"backgroundTag":null,"analyzedSha":"5159bd72e8373d215492dff122acc9d389e219c9","analyzedAt":"2026-08-15T01:59:36.292Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}