{"record":{"id":"0ce9fbf24ee7423c","repo":"datawhalechina/hello-agents","slug":"unknown-relation-type-relation","errorCode":null,"errorMessage":"Unknown relation type '{relation}'.","messagePattern":"Unknown relation type '(.+?)'\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"Co-creation-projects/BitSecret-GPSAgent/src/gps/symbolic_solver.py","lineNumber":1409,"sourceCode":"        all_goal_ids = set()\n        for father_id in father_ids:  # add sub_goals\n            operation_id = self._add_operation(('Decompose', theorem_name, theorem_paras))\n            goal_ids = self._add_goals(sub_goals, father_id, operation_id)\n            if goal_ids is not None:\n                all_goal_ids.update(goal_ids)\n\n        if len(all_goal_ids) == 0:\n            return f\"使用定理'{theorem}'分解目标{goal}失败，新分解的子目标不能是原目标的父目标。\"\n\n        self._check_goals(all_goal_ids)\n\n        result = f\"使用定理'{theorem}'分解目标{goal}成功，以下为问题的状态更新。\\n\"\n        return result + self._get_update(old_fact_id, old_goal_id, old_goal_status)\n\n    def find_fact(self, relation):\n        if relation not in self.predicate_to_fact_instances:\n            msg = f\"Unknown relation type '{relation}'.\"\n            raise Exception(msg)\n\n        if len(self.predicate_to_fact_instances) == 0:\n            return relation + f\"类型的关系列表为空，当前问题暂时未推导出{relation}关系。\"\n\n        if relation == 'Eq':\n            result = []\n            if len(self.equations) > 0:\n                result.append(\"按照方程变量是否相交来分组，得到的代数方程组（所有方程省略'=0'、组序号可能不连续）：\")\n                for group_id in self.equations:\n                    eqs = [str(eq).replace(' ', '') for eq in self.equations[group_id][0]]\n                    result.append(f'Group {group_id}: ' + ', '.join(eqs))\n            if len(self.sym_to_value) > 0:\n                result.append(\"以下是所有已经求解出值的变量：\")\n                result.append(str(self.sym_to_value))\n            return '\\n'.join(result)\n        else:\n            instances = []\n            for instance in self.predicate_to_fact_instances[relation]:","sourceCodeStart":1391,"sourceCodeEnd":1427,"githubUrl":"https://github.com/datawhalechina/hello-agents/blob/606a07d341a47be773fab7f4b71177f53f96b2c3/Co-creation-projects/BitSecret-GPSAgent/src/gps/symbolic_solver.py#L1391-L1427","documentation":"find_fact(relation) validates its argument against self.predicate_to_fact_instances, a dict grouping currently-known facts by predicate name (e.g. 'Parallel', 'Perpendicular', 'Eq'). Passing a relation string that is not a key raises this Exception. Note the logic bug: the emptiness check 'if len(self.predicate_to_fact_instances) == 0' comes after the membership check, so an unknown relation raises even when the fact table is empty instead of returning the friendly 'list is empty' message.","triggerScenarios":"Calling solver.find_fact('paralle') (typo), find_fact('parallel') with wrong casing, or a predicate that simply has no facts recorded yet in a fresh problem state — the membership check fires before any content check.","commonSituations":"Agents guessing predicate names not present in the current problem's fact table; casing/naming mismatches between GDL predicates and the relation string; querying before any facts were added or derived.","solutions":["Enumerate valid relations first: valid = sorted(solver.predicate_to_fact_instances.keys()) and pass one of those exactly.","Match the casing used by the GDL predicates (typically capitalized like 'Parallel').","If the dict is empty, add/derive facts before querying — the 'empty' friendly path is unreachable for unknown names due to the check order."],"exampleFix":"# before\nsolver.find_fact('parallel')  # wrong casing -> raises\n\n# after\nvalid = sorted(solver.predicate_to_fact_instances.keys())\nrel = next((r for r in valid if r.lower() == 'parallel'), None)\nprint(solver.find_fact(rel) if rel else f'no such relation, have {valid}')","handlingStrategy":"validation","validationCode":"def safe_find_fact(solver, relation):\n    keys = solver.predicate_to_fact_instances.keys()\n    match = next((k for k in keys if k.lower() == relation.lower()), None)\n    if match is None:\n        return f'unknown relation; valid: {sorted(keys)}'\n    return solver.find_fact(match)","typeGuard":null,"tryCatchPattern":"try:\n    print(solver.find_fact(relation))\nexcept Exception as e:\n    if str(e).startswith(\"Unknown relation type\"):\n        print('valid relations:', sorted(solver.predicate_to_fact_instances))","preventionTips":["Populate the choice of relations from predicate_to_fact_instances.keys() rather than a hardcoded list.","Case-fold matches before calling to survive casing drift.","Remember the empty-dict case still raises for unknown names — check emptiness yourself first."],"tags":["geometry","symbolic-solver","find-fact","validation"],"backgroundTag":null,"analyzedSha":"606a07d341a47be773fab7f4b71177f53f96b2c3","analyzedAt":"2026-08-14T22:57:27.446Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}