{"record":{"id":"b7c94a2912176aa5","repo":"binary-husky/gpt_academic","slug":"failed-to-analyze-query-str-e","errorCode":null,"errorMessage":"Failed to analyze query: {str(e)}","messagePattern":"Failed to analyze query: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"crazy_functions/review_fns/query_analyzer.py","lineNumber":398,"sourceCode":"            return SearchCriteria(\n                query_type=query_type,\n                main_topic=main_topic,\n                sub_topics=sub_topics,\n                start_year=start_year,\n                end_year=end_year,\n                arxiv_params=arxiv_params,\n                semantic_params=semantic_params,\n                pubmed_params=pubmed_params,\n                crossref_params=crossref_params,\n                paper_id=paper_id,\n                paper_title=paper_title,\n                paper_source=paper_source,\n                original_query=query,\n                adsabs_params=adsabs_params\n            )\n\n        except Exception as e:\n            raise Exception(f\"Failed to analyze query: {str(e)}\")\n\n    def _normalize_query_type(self, query_type: str, query: str) -> str:\n        \"\"\"规范化查询类型\"\"\"\n        if query_type in [\"review\", \"recommend\", \"qa\", \"paper\"]:\n            return query_type\n\n        query_lower = query.lower()\n        for type_name, keywords in self.valid_types.items():\n            for keyword in keywords:\n                if keyword in query_lower:\n                    return type_name\n\n        query_type_lower = query_type.lower()\n        for type_name, keywords in self.valid_types.items():\n            for keyword in keywords:\n                if keyword in query_type_lower:\n                    return type_name\n","sourceCodeStart":380,"sourceCodeEnd":416,"githubUrl":"https://github.com/binary-husky/gpt_academic/blob/d6bde0fa54373309bd05823a49bda8da019d2c77/crazy_functions/review_fns/query_analyzer.py#L380-L416","documentation":"The outermost wrapper of QueryAnalyzer.analyze: every exception raised inside the method (errors 90-93, parameter parsing, any unexpected error) is caught and re-raised as Exception('Failed to analyze query: {str(e)}'). It preserves the original message but destroys the original exception type and traceback, so diagnosis requires reading the embedded text.","triggerScenarios":"Any failure during multi-prompt LLM fan-out or downstream parsing: None responses, missing response slots, unparseable <query_type> tag, invalid arXiv/Semantic Scholar parameter blocks, or attribute errors while assembling the AnalyzedQuery result object.","commonSituations":"End users see this single message for every analyzer failure; typical underlying causes are LLM API misconfiguration (key/model), non-conforming model output, or transient API errors — all surfaced through this one wrapper.","solutions":["Read the suffix after 'Failed to analyze query:' — it names the real cause; map it to errors 90-93 if it matches.","Fix the underlying issue (API key/model config, prompt format, retry on transient failure).","In your own code, catch this exception and degrade gracefully (skip analysis, use default search parameters) rather than crashing the request pipeline.","If you control the code, re-raise with `raise Exception(...) from e` or use logging.exception to keep the traceback."],"exampleFix":"# before\nexcept Exception as e:\n    raise Exception(f'Failed to analyze query: {str(e)}')\n\n# after\nexcept Exception as e:\n    logger.exception('Query analysis failed')\n    raise Exception(f'Failed to analyze query: {str(e)}') from e","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    analyzed = analyzer.analyze(query)\nexcept Exception as e:  # 'Failed to analyze query: ...'\n    logger.warning('analysis failed (%s); using default search params', e)\n    analyzed = AnalyzedQuery(query_type='paper', original_query=query)  # safe defaults","preventionTips":["Never let analyzer failures kill the user request — default parameters keep search working.","Log the full embedded message; it identifies which sub-step (90-93) broke.","Retry once before falling back: most sub-causes are transient API errors."],"tags":["llm","error-wrapping","query-analyzer","diagnostics"],"backgroundTag":null,"analyzedSha":"d6bde0fa54373309bd05823a49bda8da019d2c77","analyzedAt":"2026-08-14T22:48:35.038Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}