{"record":{"id":"69de5c524022b96f","repo":"Zie619/n8n-workflows","slug":"error-searching-workflows-str-e","errorCode":null,"errorMessage":"Error searching workflows: {str(e)}","messagePattern":"Error searching workflows: (.+?)","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"api_server.py","lineNumber":303,"sourceCode":"                continue\n\n        pages = (total + per_page - 1) // per_page  # Ceiling division\n\n        return SearchResponse(\n            workflows=workflow_summaries,\n            total=total,\n            page=page,\n            per_page=per_page,\n            pages=pages,\n            query=q,\n            filters={\n                \"trigger\": trigger,\n                \"complexity\": complexity,\n                \"active_only\": active_only,\n            },\n        )\n    except Exception as e:\n        raise HTTPException(\n            status_code=500, detail=f\"Error searching workflows: {str(e)}\"\n        )\n\n\n@app.get(\"/api/workflows/{filename}\")\nasync def get_workflow_detail(filename: str, request: Request):\n    \"\"\"Get detailed workflow information including raw JSON.\"\"\"\n    try:\n        # Security: Validate filename to prevent path traversal\n        if not validate_filename(filename):\n            print(f\"Security: Blocked path traversal attempt for filename: {filename}\")\n            raise HTTPException(status_code=400, detail=\"Invalid filename format\")\n\n        # Security: Rate limiting\n        client_ip = request.client.host if request.client else \"unknown\"\n        if not check_rate_limit(client_ip):\n            raise HTTPException(\n                status_code=429, detail=\"Rate limit exceeded. Please try again later.\"","sourceCodeStart":285,"sourceCodeEnd":321,"githubUrl":"https://github.com/Zie619/n8n-workflows/blob/94007c1445d9258a7da116646b79473e7c7c3282/api_server.py#L285-L321","documentation":"A 500 response from GET /api/workflows when the paginated search pipeline fails. The handler calls db.search_workflows(...) and result construction inside one try block; any exception from the query engine (bad query syntax, missing table, DB connection error) is converted to HTTPException(500) containing str(e).","triggerScenarios":"GET /api/workflows?q=... where the query string breaks the DB-side search parser (e.g. unmatched quotes producing filename:\"...-style phrases), calling the endpoint against a missing/corrupt SQLite database, or page/per_page edge values that trip arithmetic on None totals.","commonSituations":"Typing a stray double-quote in the UI search box (the detail endpoint itself builds f'filename:\"{filename}\"' queries); switching database files mid-run; schema drift between the indexer and the query code after a partial upgrade.","solutions":["Retry the request with an empty q parameter to see whether the query text or the database is at fault.","Verify the database is built and current by checking GET /api/stats; rebuild via the reindex flow if stats also fail.","Strip or escape double quotes from user-supplied q before it reaches the search parser.","Read the server log: the detail field carries the exact exception message from db.search_workflows."],"exampleFix":"# before\nresults, total = db.search_workflows(q, ...)\n\n# after (sanitize quotes that break the query parser)\nsafe_q = q.replace('\"', \"'\")\nresults, total = db.search_workflows(safe_q, ...)","handlingStrategy":"try-catch","validationCode":"def safe_query(q: str) -> str:\n    # strip characters the search parser treats specially\n    return q.replace('\"', '').replace(':', ' ')","typeGuard":null,"tryCatchPattern":"try:\n    resp = client.get('/api/workflows', params={'q': q})\n    resp.raise_for_status()\nexcept HTTPError as e:\n    if e.response.status_code == 500:\n        retry_with_empty_q_or_report(e.response.json().get('detail'))","preventionTips":["Sanitize user-supplied q (remove quotes/colons) before sending.","Fall back to an empty query on 500 to distinguish parser issues from DB issues.","Monitor server logs — the detail string embeds the root exception."],"tags":["fastapi","search","database","query-escaping"],"backgroundTag":null,"analyzedSha":"94007c1445d9258a7da116646b79473e7c7c3282","analyzedAt":"2026-08-15T04:10:37.591Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}