{"record":{"id":"04eadb34d3081fe8","repo":"toeverything/AFFiNE","slug":"param-not-a-number-mode-numbetoken-text","errorCode":null,"errorMessage":"Param not a number: ${mode},${numbeToken.text}","messagePattern":"Param not a number: (.+?),(.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"blocksuite/affine/blocks/surface/src/utils/path-data-parser/parser.ts","lineNumber":103,"sourceCode":"        paramsCount = PARAMS[token.text];\n        mode = token.text;\n      } else {\n        return parsePath('M0,0' + d);\n      }\n    } else if (isType(token, NUMBER)) {\n      paramsCount = PARAMS[mode];\n    } else {\n      index++;\n      paramsCount = PARAMS[token.text];\n      mode = token.text;\n    }\n    if (index + paramsCount < tokens.length) {\n      for (let i = index; i < index + paramsCount; i++) {\n        const numbeToken = tokens[i];\n        if (isType(numbeToken, NUMBER)) {\n          params[params.length] = +numbeToken.text;\n        } else {\n          throw new Error(\n            'Param not a number: ' + mode + ',' + numbeToken.text\n          );\n        }\n      }\n      if (typeof PARAMS[mode] === 'number') {\n        const segment: Segment = { key: mode, data: params };\n        segments.push(segment);\n        index += paramsCount;\n        token = tokens[index];\n        if (mode === 'M') mode = 'L';\n        if (mode === 'm') mode = 'l';\n      } else {\n        throw new Error('Bad segment: ' + mode);\n      }\n    } else {\n      throw new Error('Path data ended short');\n    }\n  }","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/toeverything/AFFiNE/blob/26c515e050211269e911f7d9cfe162a26c83ed98/blocksuite/affine/blocks/surface/src/utils/path-data-parser/parser.ts#L85-L121","documentation":"Thrown by parsePath (SVG path-data parser used by the surface renderer) when, while collecting the parameters for a path command, one of the tokens expected to be a NUMBER is not a number token. The parser tokenises an SVG path 'd' string; each command (M/L/C/Q/...) has a fixed parameter count (PARAMS), and after reading the command it iterates the next paramsCount tokens demanding they all be numbers. A non-number token at a parameter position yields this error with the offending mode and token text.","triggerScenarios":"Calling parsePath(d) with a malformed SVG path string where a letter/command appears where a number is expected, e.g. 'M10,L20' (a stray command mid-params) or 'L 10 x 20'. Also when the tokenizer falls through because the regex could not classify a token but the upper bound check still passes.","commonSituations":"Loading a shape/mindmap/connector whose path data is hand-edited or produced by a buggy exporter; copy-pasting SVG path strings from external sources; corrupt surface block data; locale-specific number formatting (comma decimal separators) mis-tokenised.","solutions":["Validate/sanitise the SVG path string before calling parsePath: ensure numbers use '.' as decimal separator and no stray command letters appear inside parameter runs.","Run the path through a normaliser (e.g. an SVG-path normalise library) before parsing.","Wrap parsePath in try/catch and fall back to a safe default path (or skip the element) on malformed input."],"exampleFix":"// before\nparsePath(userPathString); // 'M10,L20' -> throws\n\n// after\ntry {\n  parsePath(userPathString);\n} catch (e) {\n  // fall back: skip element or use default path\n  segments = parsePath('M0,0 L0,0');\n}","handlingStrategy":"try-catch","validationCode":"function normalisePath(d) {\n  return d.replace(/,/g, ' ').replace(/\\s+/g, ' ').trim();\n}\n// ensure decimal points are '.' and no stray letters inside number runs before parsing\nparsePath(normalisePath(rawPath));","typeGuard":null,"tryCatchPattern":"let segments;\ntry { segments = parsePath(rawPath); }\ncatch (e) {\n  // fall back to a safe default path\n  segments = parsePath('M0,0 L0,0');\n}","preventionTips":["Validate SVG path strings before parsing; reject unknown letters inside parameter runs.","Normalise number formatting (use '.' as decimal separator).","Wrap parsePath in try/catch and degrade to a default path on malformed input."],"tags":["svg","path-parser","parsing","surface"],"backgroundTag":null,"analyzedSha":"26c515e050211269e911f7d9cfe162a26c83ed98","analyzedAt":"2026-08-12T13:15:16.447Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}