{"record":{"id":"9f5ca16e3169d268","repo":"larksuite/cli","slug":"message","errorCode":null,"errorMessage":"{message}","messagePattern":"\\{message\\}","errorType":"exception","errorClass":"IconParkToolError","httpStatus":null,"severity":"error","filePath":"skills/lark-slides/scripts/iconpark_tool.py","lineNumber":51,"sourceCode":"    \"安全\": {\"iconpark/Safe/protect.svg\"},\n    \"防护\": {\"iconpark/Safe/protect.svg\"},\n    \"全球\": {\"iconpark/Travel/world.svg\"},\n    \"市场\": {\"iconpark/Travel/world.svg\"},\n    \"邮件\": {\"iconpark/Office/envelope-one.svg\"},\n    \"联系\": {\"iconpark/Office/envelope-one.svg\"},\n    \"会议\": {\"iconpark/Office/schedule.svg\"},\n    \"日程\": {\"iconpark/Office/schedule.svg\"},\n    \"飞书\": {\"iconpark/Brand/bydesign.svg\"},\n}\nCURATED_BOOST_SCORE = 40\n\n\nclass IconParkToolError(Exception):\n    pass\n\n\ndef fail(message: str) -> None:\n    raise IconParkToolError(message)\n\n\ndef normalize_whitespace(value: str) -> str:\n    return re.sub(r\"\\s+\", \" \", value).strip()\n\n\ndef normalize_token(value: str) -> str:\n    return normalize_whitespace(value.lower().replace(\"_\", \"-\"))\n\n\ndef append_unique(target: list[str], token: str) -> None:\n    normalized = normalize_token(token)\n    if normalized and normalized not in target:\n        target.append(normalized)\n\n\ndef tokenize_query(value: str) -> list[str]:\n    normalized = normalize_token(value)","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/skills/lark-slides/scripts/iconpark_tool.py#L33-L69","documentation":"fail() is the single error-raising helper of the iconpark_tool script: it always raises IconParkToolError with the supplied message. Every CLI stage (index loading, --limit parsing, icon search, icon resolution, argument parsing) funnels its failure through fail(), so all iconpark_tool errors surface as IconParkToolError with the raw text as the message. It is a controlled failure meant to be caught or printed by the CLI's top-level handler.","triggerScenarios":"Any invalid input or state in the iconpark CLI: load_index on a missing/corrupt index file, parse_limit with a non-positive or non-integer --limit, search_icons with an empty/unknown query, resolve_icon with an unknown icon id, or run_cli catching malformed arguments.","commonSituations":"Running the icon search script before its IconPark index has been generated/downloaded; typos in icon names; passing --limit 0 or --limit abc; stale index after an IconPark package update.","solutions":["Read the exception message for the specific cause and fix the corresponding input (correct icon name, positive integer --limit, valid index path).","Regenerate or re-download the IconPark index if load_index reported it missing or corrupt, then retry.","Wrap calls in try/except IconParkToolError when embedding the script as a library, and surface err.args[0] to your user.","Run with --help (or inspect parse_cli_args) to confirm accepted flags and value ranges before retrying."],"exampleFix":"// before\nresult = run_cli([\"search\", \"--limit\", \"0\"])\n# IconParkToolError: limit must be a positive integer\n\n// after\ntry:\n    result = run_cli([\"search\", \"--limit\", \"10\"])\nexcept IconParkToolError as err:\n    print(f\"iconpark: {err}\")","handlingStrategy":"try-catch","validationCode":"if not index_path.exists():\n    raise SystemExit(f\"index file missing: {index_path}; regenerate it first\")\nlimit = args.limit\nif not isinstance(limit, int) or limit <= 0:\n    raise SystemExit(\"--limit must be a positive integer\")","typeGuard":null,"tryCatchPattern":"try:\n    run_cli(argv)\nexcept IconParkToolError as err:\n    print(f\"iconpark error: {err}\", file=sys.stderr)\n    sys.exit(2)","preventionTips":["Validate --limit and icon-name arguments before calling the tool functions.","Keep the IconPark index regenerated after package upgrades.","Catch IconParkToolError specifically (it is the script's only failure type) rather than bare Exception.","Tab-complete or list icons before resolving an id/name."],"tags":["python","cli","iconpark","custom-exception"],"backgroundTag":"invalid-cli-argument","analyzedSha":"7fd6ef3c07182257ce776cdc5a614e122d5bd4b3","analyzedAt":"2026-09-04T21:17:44.649Z","contentChangedAt":"2026-09-04T21:17:44.649Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}