{"record":{"id":"747eff9a0f787e17","repo":"datawhalechina/hello-agents","slug":"error-repr-e-occurred-while-parsing-the-theor","errorCode":null,"errorMessage":"Error '{repr(e)}' occurred while parsing the theorem '{theorem}'. The theorem format is incorrect.","messagePattern":"Error '(.+?)' occurred while parsing the theorem '(.+?)'\\. The theorem format is incorrect\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"Co-creation-projects/BitSecret-GPSAgent/src/gps/symbolic_solver.py","lineNumber":1257,"sourceCode":"                            if old_goal_status[goal_id] != self.status_of_goal[goal_id]]\n        if len(updated_goal_ids) > 0:\n            result.append(\n                '部分目标的状态更新为（括号内数字表示目标状态，0表示此目标待求解，1表示此目标已求解，-1表示此目标不可能实现）：'\n            )\n            for goal_id in updated_goal_ids:\n                goal = _anti_parse_fact((self.goals[goal_id][0], self.goals[goal_id][1]))\n                goal = goal + f'({self.status_of_goal[goal_id]})'\n                result.append(goal)\n\n        return '\\n'.join(result)\n\n    def _parse_theorem(self, theorem):\n        try:\n            theorem_name, theorem_paras = parse_fact(theorem.replace(' ', ''))\n        except Exception as e:\n            e_msg = (f\"Error '{repr(e)}' occurred while parsing the theorem '{theorem}'. \"\n                     f\"The theorem format is incorrect.\")\n            raise Exception(e_msg)\n\n        if theorem_name not in self.parsed_gdl[\"Theorems\"]:\n            e_msg = f\"Unknown theorem name: '{theorem_name}'.\"\n            raise Exception(e_msg)\n\n        error_paras = set([char for char in theorem_paras if not char.isupper()])\n        if len(error_paras) > 0:\n            e_msg = (f\"Theorem parameters must be uppercase letters and , only. \"\n                     f\"The current theorem contains invalid characters '{str(error_paras)}'.\")\n            raise Exception(e_msg)\n\n        if len(theorem_paras) != 0 and len(theorem_paras) != len(self.parsed_gdl[\"Theorems\"][theorem_name]['paras']):\n            e_msg = (f\"'{theorem}' has wrong number of parameters \"\n                     f\"(expected {len(self.parsed_gdl[\"Theorems\"][theorem_name]['paras'])}).\")\n            raise Exception(e_msg)\n\n        if len(theorem_paras) == 0:\n            theorem_paras = None","sourceCodeStart":1239,"sourceCodeEnd":1275,"githubUrl":"https://github.com/datawhalechina/hello-agents/blob/606a07d341a47be773fab7f4b71177f53f96b2c3/Co-creation-projects/BitSecret-GPSAgent/src/gps/symbolic_solver.py#L1239-L1275","documentation":"An exception raised by SymbolicSolver._parse_theorem (src/gps/symbolic_solver.py) when parse_fact throws on the theorem string. The theorem is expected in the form Name(Upper,Case,Paras); parse_fact failing means the string deviates from that grammar — missing/mismatched parentheses, empty name, stray separators, or unbalanced quotes — and the code surfaces the underlying repr(e) plus the offending theorem text.","triggerScenarios":"Calling any API that loads or applies theorems — e.g. solving with a custom GDL, applying a theorem by name via the solver, or loading a theorem knowledge file — with a malformed entry like 'midpoint(' , ' (A,B)', 'isosceles_triangle,A,B', or a name containing spaces after the replace(' ','') normalizes away structure. The replace(' ','') happens before parsing, so whitespace inside the name silently concatenates tokens and can also produce this error.","commonSituations":"Hand-editing a GDL/theorem YAML and breaking parentheses; LLM-generated theorem strings with trailing commas or full-width Chinese parentheses （） that parse_fact rejects; data files saved with trailing whitespace/newlines inside strings; name typos that drop the opening parenthesis entirely.","solutions":["Look at the printed theorem string and align it to the exact 'Name(P1,P2,...)' grammar with ASCII parentheses and commas","Add a lint step over your GDL/theorem file: try parse_fact(t.replace(' ','')) for each entry and report failures before runtime","If importing data authored in Chinese IME, normalize full-width （）， to (), before parsing","Extend _parse_theorem's error path to include the expected format in the message for faster diagnosis"],"exampleFix":"# before (GDL entry)\n# theorem: \"tangent_of_circle（O,A）\"   # full-width parens -> parse_fact raises\n\n# after\n# theorem: \"tangent_of_circle(O,A)\"","handlingStrategy":"validation","validationCode":"def lint_theorem(t: str) -> bool:\n    t = t.replace(' ', '').replace('（', '(').replace('）', ')').replace('，', ',')\n    try:\n        name, paras = parse_fact(t)\n        return bool(name) and all(p.isupper() for p in paras)\n    except Exception:\n        return False\n\nassert lint_theorem(theorem_str), f'malformed theorem: {theorem_str!r}'","typeGuard":"def is_wellformed_theorem(t: str) -> bool:\n    t = t.replace(' ', '')\n    return '(' in t and t.endswith(')') and t.index('(') > 0","tryCatchPattern":"try:\n    solver._parse_theorem(theorem)\nexcept Exception as e:\n    if 'format is incorrect' in str(e):\n        log_authoring_error(theorem=theorem, expected='Name(P1,P2,...)')\n        continue  # skip bad entry, keep loading the rest\n    raise","preventionTips":["Normalize full-width parentheses/commas from CJK input before parsing","Lint every theorem entry in GDL files with parse_fact during CI","Keep the exact 'Name(Upper,Paras)' grammar when authoring theorem strings"],"tags":["geometry","solver","parsing","theorem","cdl"],"backgroundTag":null,"analyzedSha":"606a07d341a47be773fab7f4b71177f53f96b2c3","analyzedAt":"2026-08-14T22:57:27.446Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}