Skip to content

Commit 052d55d

Browse files
errors: +59 patterns covering 868 → 927 niches
Broader runtime + parser + autograd coverage: parser: unterminated string/comment, invalid number/character, trailing comma, unexpected newline, indent error arrays: invalid index type, negative index (Python-ism) dicts: dict numeric key, missing field runtime: write to const, ambiguous import, function shadow, operator overload missing, comparison undefined, interface mismatch, instance schema drift, private access convention, static/instance method confusion, missing super call, override conflict, unknown/misplaced pragma, reserved field name, method binding error, infinite recursion strings: invalid UTF-8, encoding error math: zero divisor, NaN propagation, loss of precision autograd: stale tape reference, gradient propagation broken, backward without forward, loss not scalar, shape mismatch in matmul, wrong rank, tape memory leak python-ism: yield in expression, await not supported hashing: inappropriate hash (function/closure) Plus 12 "X requires Y type" patterns for ML kernels and a few bound-check patterns. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent b372db8 commit 052d55d

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

omnimcode-core/src/errors.rs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,6 +1179,65 @@ pub const ERROR_PATTERNS: &[ErrorPattern] = &[
11791179
ErrorPattern { pattern: "overflow shift", category: "math", explanation: "Shift exceeded i64 width.", typical_cause: "Shift count out of range.", fix: "Mask shift count to 0..63 via & 63." },
11801180
ErrorPattern { pattern: "invalid base", category: "math", explanation: "parse_int with base outside 2..36.", typical_cause: "Wrong base.", fix: "Use base in [2, 36]." },
11811181
ErrorPattern { pattern: "not a multiple", category: "math", explanation: "Requires divisibility but input isn't a multiple.", typical_cause: "Bad input.", fix: "Use modular arithmetic or pad input." },
1182+
ErrorPattern { pattern: "unterminated string", category: "parser", explanation: "String literal lacks closing quote.", typical_cause: "Forgot a closing \" or '.", fix: "Add the missing quote; check escape sequences inside." },
1183+
ErrorPattern { pattern: "unterminated comment", category: "parser", explanation: "Block comment lacks closing */.", typical_cause: "Missing close marker.", fix: "Add */ at the end of the comment." },
1184+
ErrorPattern { pattern: "invalid number", category: "parser", explanation: "Number literal couldn't be parsed.", typical_cause: "Bad digit/separator.", fix: "Use standard syntax: 42 or 3.14 or 1e9." },
1185+
ErrorPattern { pattern: "invalid character", category: "parser", explanation: "Lexer encountered a character it doesn't accept.", typical_cause: "Pasted non-ASCII or stray symbol.", fix: "Remove the unexpected character." },
1186+
ErrorPattern { pattern: "trailing comma", category: "parser", explanation: "Comma without following element.", typical_cause: "Extra , at end of list/args.", fix: "Remove the trailing comma." },
1187+
ErrorPattern { pattern: "unexpected newline", category: "parser", explanation: "Newline where one isn't allowed.", typical_cause: "Statement terminator confusion.", fix: "Continue the expression or add a semicolon." },
1188+
ErrorPattern { pattern: "indent error", category: "parser", explanation: "Indentation inconsistent.", typical_cause: "Mixed tabs and spaces.", fix: "Use one or the other consistently (4 spaces canonical)." },
1189+
ErrorPattern { pattern: "invalid index type", category: "arrays", explanation: "Index must be an integer.", typical_cause: "Passed a float or string.", fix: "Coerce: arr_get(xs, to_int(x))." },
1190+
ErrorPattern { pattern: "negative index", category: "arrays", explanation: "Negative indices not supported (use len - n).", typical_cause: "Coming from Python's [-1].", fix: "arr_get(xs, arr_len(xs) - 1) for last element." },
1191+
ErrorPattern { pattern: "dict numeric key", category: "dicts", explanation: "Dict keys are strings; got int.", typical_cause: "Trying d[0].", fix: "to_string(0) the key or use an array." },
1192+
ErrorPattern { pattern: "write to const", category: "runtime", explanation: "Tried to reassign a constant binding.", typical_cause: "Re-binding tape_const value.", fix: "Use a different node id or fresh tape_var." },
1193+
ErrorPattern { pattern: "ambiguous import", category: "imports", explanation: "Two imports provide the same name.", typical_cause: "Selective imports collide.", fix: "Use module alias or rename." },
1194+
ErrorPattern { pattern: "function shadow", category: "runtime", explanation: "Local binding shadows a builtin.", typical_cause: "Variable name matches builtin.", fix: "Rename the variable." },
1195+
ErrorPattern { pattern: "operator overload missing", category: "runtime", explanation: "No operator + for these types.", typical_cause: "Trying to add dict + dict.", fix: "Use explicit dict_merge." },
1196+
ErrorPattern { pattern: "comparison undefined", category: "runtime", explanation: "< / > / <= / >= not defined between these types.", typical_cause: "Comparing dict to int.", fix: "Coerce or compare specific fields." },
1197+
ErrorPattern { pattern: "missing field", category: "runtime", explanation: "Dict access for a key not present.", typical_cause: "Stale schema assumption.", fix: "dict_has first or dict_get_or with default." },
1198+
ErrorPattern { pattern: "interface mismatch", category: "runtime", explanation: "Object lacks method expected by call site.", typical_cause: "Class missing the method.", fix: "Add the method to the class or its parents." },
1199+
ErrorPattern { pattern: "instance fields differ", category: "runtime", explanation: "Two instances have different fields.", typical_cause: "Schema drift.", fix: "Establish a canonical schema or use dict_get_or." },
1200+
ErrorPattern { pattern: "infinite recursion", category: "runtime", explanation: "Recursion exceeded stack budget.", typical_cause: "Base case unreachable.", fix: "Verify the recursive call moves toward the base case." },
1201+
ErrorPattern { pattern: "invalid utf-8 sequence", category: "strings", explanation: "Bytes don't form valid UTF-8.", typical_cause: "Reading binary as string.", fix: "Sanitize input or use bytes-typed buffers." },
1202+
ErrorPattern { pattern: "encoding error", category: "stdlib", explanation: "Character outside expected encoding.", typical_cause: "Mixing encodings.", fix: "Normalize to UTF-8." },
1203+
ErrorPattern { pattern: "zero divisor", category: "math", explanation: "Division by zero attempted.", typical_cause: "Computed divisor was 0.", fix: "Guard: `if denom != 0 { ... }`." },
1204+
ErrorPattern { pattern: "nan propagation", category: "math", explanation: "Operation involves NaN.", typical_cause: "Earlier computation produced NaN.", fix: "Trace back; guard NaN sources." },
1205+
ErrorPattern { pattern: "loss of precision", category: "math", explanation: "Float lost significant digits.", typical_cause: "Big subtraction of close values.", fix: "Use Kahan summation / scale inputs." },
1206+
ErrorPattern { pattern: "inappropriate hash", category: "stdlib", explanation: "Type can't be hashed.", typical_cause: "Hashing a circuit/function/closure.", fix: "Hash a derived stable value (e.g. its name)." },
1207+
ErrorPattern { pattern: "yield in expression", category: "generators", explanation: "yield used as expression, not statement.", typical_cause: "Pythonism.", fix: "OMC yield is statement-only." },
1208+
ErrorPattern { pattern: "await not supported", category: "generators", explanation: "OMC has no async/await.", typical_cause: "Pasted Python async code.", fix: "Refactor with lazy gen_stream + callbacks." },
1209+
ErrorPattern { pattern: "private access", category: "runtime", explanation: "Class fields are public; underscore-prefix is convention only.", typical_cause: "Expecting Python-style _name privacy.", fix: "Treat _name as convention; document intent." },
1210+
ErrorPattern { pattern: "static call on instance", category: "runtime", explanation: "Static method invoked via instance.", typical_cause: "Confusion between instance and class.", fix: "Call via Class.method(...) (without dot)." },
1211+
ErrorPattern { pattern: "instance call on class", category: "runtime", explanation: "Instance method invoked without receiver.", typical_cause: "Forgot to construct an instance.", fix: "Build instance via Class(args) first." },
1212+
ErrorPattern { pattern: "missing super call", category: "runtime", explanation: "Parent class init/method not invoked from child.", typical_cause: "Forgot to call parent init.", fix: "Explicit Parent__init(self, args)." },
1213+
ErrorPattern { pattern: "Override conflict", category: "runtime", explanation: "Child method has different arity than parent.", typical_cause: "Refactor changed signature.", fix: "Match the signature or refactor the parent." },
1214+
ErrorPattern { pattern: "Unknown pragma", category: "parser", explanation: "Unrecognized @pragma directive.", typical_cause: "Typo or pragma not implemented.", fix: "Check known pragmas: @harmony, @predict, @hbit, @no_heal." },
1215+
ErrorPattern { pattern: "Pragma misplaced", category: "parser", explanation: "@pragma in wrong position.", typical_cause: "Pragmas come before fn.", fix: "Move @pragma above fn." },
1216+
ErrorPattern { pattern: "Reserved field name", category: "runtime", explanation: "Class field uses reserved name.", typical_cause: "Using __class__ as a regular field.", fix: "Rename the field; __class__ is reserved." },
1217+
ErrorPattern { pattern: "Method binding error", category: "runtime", explanation: "Cannot bind method to non-instance receiver.", typical_cause: "Calling instance method on null/scalar.", fix: "Verify receiver type with is_instance." },
1218+
ErrorPattern { pattern: "Stale tape reference", category: "autograd", explanation: "tape_grad/tape_value on id from before tape_reset.", typical_cause: "Reused stale id.", fix: "Capture ids inside the current tape_reset() block." },
1219+
ErrorPattern { pattern: "Gradient propagation broken", category: "autograd", explanation: "All gradients zero — graph disconnected.", typical_cause: "Used tape_const where tape_var needed.", fix: "Use tape_var for parameters, tape_const for inputs." },
1220+
ErrorPattern { pattern: "Backward without forward", category: "autograd", explanation: "tape_backward called before any tape ops.", typical_cause: "Empty tape.", fix: "Build a forward graph first via tape_var / tape_mul / etc." },
1221+
ErrorPattern { pattern: "Loss not scalar", category: "autograd", explanation: "tape_backward expects a scalar-valued node.", typical_cause: "Loss was a vector/matrix.", fix: "Add tape_sum or tape_mean to reduce." },
1222+
ErrorPattern { pattern: "Shape mismatch in matmul", category: "autograd", explanation: "tape_matmul shape mismatch (A.cols != B.rows).", typical_cause: "Wrong matrix dims.", fix: "Transpose one operand or fix dims." },
1223+
ErrorPattern { pattern: "Wrong rank for tape op", category: "autograd", explanation: "tape op got wrong-rank tensor.", typical_cause: "1D where 2D expected.", fix: "Wrap in [[...]] for 1×N row." },
1224+
ErrorPattern { pattern: "Tape memory leak", category: "autograd", explanation: "Tape grew unboundedly.", typical_cause: "Forgot tape_reset() between iterations.", fix: "tape_reset() at start of each step." },
1225+
ErrorPattern { pattern: "arr_softmax: requires array", category: "types", explanation: "`arr_softmax` got the wrong shape/type.", typical_cause: "Expected array (float[]).", fix: "Wrap with appropriate type or convert; check type_of(value)." },
1226+
ErrorPattern { pattern: "arr_layer_norm: requires array", category: "types", explanation: "`arr_layer_norm` got the wrong shape/type.", typical_cause: "Expected array (float[]).", fix: "Wrap with appropriate type or convert; check type_of(value)." },
1227+
ErrorPattern { pattern: "arr_relu_vec: requires array", category: "types", explanation: "`arr_relu_vec` got the wrong shape/type.", typical_cause: "Expected array (float[]).", fix: "Wrap with appropriate type or convert; check type_of(value)." },
1228+
ErrorPattern { pattern: "arr_sigmoid_vec: requires array", category: "types", explanation: "`arr_sigmoid_vec` got the wrong shape/type.", typical_cause: "Expected array (float[]).", fix: "Wrap with appropriate type or convert; check type_of(value)." },
1229+
ErrorPattern { pattern: "arr_conv1d: requires two arrays", category: "types", explanation: "`arr_conv1d` got the wrong shape/type.", typical_cause: "Expected two arrays ((float[], float[])).", fix: "Wrap with appropriate type or convert; check type_of(value)." },
1230+
ErrorPattern { pattern: "arr_outer: requires two arrays", category: "types", explanation: "`arr_outer` got the wrong shape/type.", typical_cause: "Expected two arrays ((array, array)).", fix: "Wrap with appropriate type or convert; check type_of(value)." },
1231+
ErrorPattern { pattern: "arr_matmul: requires two matrices", category: "types", explanation: "`arr_matmul` got the wrong shape/type.", typical_cause: "Expected two matrices ((matrix, matrix)).", fix: "Wrap with appropriate type or convert; check type_of(value)." },
1232+
ErrorPattern { pattern: "arr_transpose: requires a 2D matrix", category: "types", explanation: "`arr_transpose` got the wrong shape/type.", typical_cause: "Expected a 2D matrix (matrix).", fix: "Wrap with appropriate type or convert; check type_of(value)." },
1233+
ErrorPattern { pattern: "arr_eye: requires an integer size", category: "types", explanation: "`arr_eye` got the wrong shape/type.", typical_cause: "Expected an integer size (int).", fix: "Wrap with appropriate type or convert; check type_of(value)." },
1234+
ErrorPattern { pattern: "arr_zeros_2d: requires two integer sizes", category: "types", explanation: "`arr_zeros_2d` got the wrong shape/type.", typical_cause: "Expected two integer sizes ((int, int)).", fix: "Wrap with appropriate type or convert; check type_of(value)." },
1235+
ErrorPattern { pattern: "arr_substrate_attention: requires three matrices", category: "types", explanation: "`arr_substrate_attention` got the wrong shape/type.", typical_cause: "Expected three matrices ((Q, K, V)).", fix: "Wrap with appropriate type or convert; check type_of(value)." },
1236+
ErrorPattern { pattern: "arr_substrate_score_rows: requires a 2D matrix", category: "types", explanation: "`arr_substrate_score_rows` got the wrong shape/type.", typical_cause: "Expected a 2D matrix (matrix).", fix: "Wrap with appropriate type or convert; check type_of(value)." },
1237+
ErrorPattern { pattern: "dict_get: bound check", category: "runtime", explanation: "`dict_get` triggered a bounds check.", typical_cause: "Index/range outside valid bounds.", fix: "Guard with length/key check before access." },
1238+
ErrorPattern { pattern: "arr_get: bound check", category: "runtime", explanation: "`arr_get` triggered a bounds check.", typical_cause: "Index/range outside valid bounds.", fix: "Guard with length/key check before access." },
1239+
ErrorPattern { pattern: "str_slice: bound check", category: "runtime", explanation: "`str_slice` triggered a bounds check.", typical_cause: "Index/range outside valid bounds.", fix: "Guard with length/key check before access." },
1240+
ErrorPattern { pattern: "arr_slice: bound check", category: "runtime", explanation: "`arr_slice` triggered a bounds check.", typical_cause: "Index/range outside valid bounds.", fix: "Guard with length/key check before access." },
11821241
];
11831242

11841243
/// Best-matching pattern for an error message. Returns None if no

0 commit comments

Comments
 (0)