{"record":{"id":"57155842880fec80","repo":"ssssssss-team/spider-flow","slug":"there-is-no-line-n-doc-first-in-the-do","errorCode":null,"errorMessage":"There is no line \" + (n + doc.first) + \" in the document.","messagePattern":"There is no line \" \\+ \\(n \\+ doc\\.first\\) \\+ \" in the document\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"spider-flow-web/src/main/resources/static/js/codemirror/codemirror.js","lineNumber":876,"sourceCode":"  StringStream.prototype.current = function (){return this.string.slice(this.start, this.pos)};\n  StringStream.prototype.hideFirstChars = function (n, inner) {\n    this.lineStart += n;\n    try { return inner() }\n    finally { this.lineStart -= n; }\n  };\n  StringStream.prototype.lookAhead = function (n) {\n    var oracle = this.lineOracle;\n    return oracle && oracle.lookAhead(n)\n  };\n  StringStream.prototype.baseToken = function () {\n    var oracle = this.lineOracle;\n    return oracle && oracle.baseToken(this.pos)\n  };\n\n  // Find the line object corresponding to the given line number.\n  function getLine(doc, n) {\n    n -= doc.first;\n    if (n < 0 || n >= doc.size) { throw new Error(\"There is no line \" + (n + doc.first) + \" in the document.\") }\n    var chunk = doc;\n    while (!chunk.lines) {\n      for (var i = 0;; ++i) {\n        var child = chunk.children[i], sz = child.chunkSize();\n        if (n < sz) { chunk = child; break }\n        n -= sz;\n      }\n    }\n    return chunk.lines[n]\n  }\n\n  // Get the part of a document between two positions, as an array of\n  // strings.\n  function getBetween(doc, start, end) {\n    var out = [], n = start.line;\n    doc.iter(start.line, end.line + 1, function (line) {\n      var text = line.text;\n      if (n == end.line) { text = text.slice(0, end.ch); }","sourceCodeStart":858,"sourceCodeEnd":894,"githubUrl":"https://github.com/ssssssss-team/spider-flow/blob/c799cca99c7d064673dc79e6ef06a08bbc0e292d/spider-flow-web/src/main/resources/static/js/codemirror/codemirror.js#L858-L894","documentation":"CodeMirror's internal getLine() validates a line number against the document before descending the line-chunk tree. If the number is negative or >= doc.size it throws this error, meaning code asked the document for a line that does not exist.","triggerScenarios":"Calling editor.getLine(n), doc.getLineHandle(n), getRange/setBookmark/markText/etc. with a line index that is negative, >= doc.lineCount(), or on a document that has since been shrunk by a change event before the index was recomputed.","commonSituations":"Off-by-one arithmetic (using doc.size instead of lineCount()-1), caching line numbers across asynchronous edits, iterating lines while deletions shrink the document, or plugins passing stale pos.line values.","solutions":["Clamp/validate the line number against cm.lineCount() (0-based) before use","Re-fetch line numbers from current positions/handles inside change handlers instead of caching them","Use CodeMirror.posFromIndex/clipPos to normalize positions into the document"],"exampleFix":"// before\nvar line = cm.getLine(savedLine);\n// after\nvar n = Math.min(savedLine, cm.lineCount() - 1);\nvar line = n >= 0 ? cm.getLine(n) : null;","handlingStrategy":"validation","validationCode":"function lineExists(cm, n) {\n  return Number.isInteger(n) && n >= 0 && n < cm.lineCount();\n}\nif (!lineExists(cm, n)) return; // or clamp: n = Math.max(0, Math.min(n, cm.lineCount()-1));","typeGuard":"function isValidLine(doc, n) {\n  return typeof n === \"number\" && n >= doc.first && n - doc.first < doc.size;\n}","tryCatchPattern":"try {\n  var line = cm.getLine(n);\n} catch (e) {\n  if (/no line \\d+ in the document/.test(e.message)) {\n    line = null; // stale index after edit; recompute from cm.posFromIndex or marks\n  } else { throw e; }\n}","preventionTips":["Remember line numbers are 0-based and bounded by cm.lineCount()-1, not doc.size","Recompute positions inside change/display events instead of caching indices across edits","Use cm.clipPos() or posFromIndex() to normalize any external position before use"],"tags":["codemirror","index-out-of-bounds","document-line"],"backgroundTag":"index-out-of-range","analyzedSha":"c799cca99c7d064673dc79e6ef06a08bbc0e292d","analyzedAt":"2026-09-08T13:47:08.225Z","contentChangedAt":"2026-09-08T13:47:08.225Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}