{"record":{"id":"376b82be6391f4f6","repo":"ssssssss-team/spider-flow","slug":"this-document-is-already-in-use","errorCode":null,"errorMessage":"This document is already in use.","messagePattern":"This document is already in use\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"spider-flow-web/src/main/resources/static/js/codemirror/codemirror.js","lineNumber":4765,"sourceCode":"\n  // Call f for all linked documents.\n  function linkedDocs(doc, f, sharedHistOnly) {\n    function propagate(doc, skip, sharedHist) {\n      if (doc.linked) { for (var i = 0; i < doc.linked.length; ++i) {\n        var rel = doc.linked[i];\n        if (rel.doc == skip) { continue }\n        var shared = sharedHist && rel.sharedHist;\n        if (sharedHistOnly && !shared) { continue }\n        f(rel.doc, shared);\n        propagate(rel.doc, doc, shared);\n      } }\n    }\n    propagate(doc, null, true);\n  }\n\n  // Attach a document to an editor.\n  function attachDoc(cm, doc) {\n    if (doc.cm) { throw new Error(\"This document is already in use.\") }\n    cm.doc = doc;\n    doc.cm = cm;\n    estimateLineHeights(cm);\n    loadMode(cm);\n    setDirectionClass(cm);\n    if (!cm.options.lineWrapping) { findMaxLine(cm); }\n    cm.options.mode = doc.modeOption;\n    regChange(cm);\n  }\n\n  function setDirectionClass(cm) {\n  (cm.doc.direction == \"rtl\" ? addClass : rmClass)(cm.display.lineDiv, \"CodeMirror-rtl\");\n  }\n\n  function directionChanged(cm) {\n    runInOp(cm, function () {\n      setDirectionClass(cm);\n      regChange(cm);","sourceCodeStart":4747,"sourceCodeEnd":4783,"githubUrl":"https://github.com/ssssssss-team/spider-flow/blob/c799cca99c7d064673dc79e6ef06a08bbc0e292d/spider-flow-web/src/main/resources/static/js/codemirror/codemirror.js#L4747-L4783","documentation":"Generic sentinel error in CodeMirror's document model: an operation (typically attaching a document to a second editor or creating a linked doc copy) targeted a Doc whose cm property is already set, meaning the document is already owned by an editor instance. CodeMirror deliberately forbids sharing one Doc between two editors unless it is explicitly linked, so the guard throws instead of silently corrupting editor state.","triggerScenarios":"Calling cm.swapDoc(doc) or new CodeMirror(el, {value: doc}) / CodeMirror(el, doc) with a Doc that is already attached to another (live) editor, or re-attaching the same doc to the same editor.","commonSituations":"Sharing one Doc between split-pane editors, reusing a doc stored on a closed-but-not-detached editor, or restoring editor state from a cache where docs weren't detached.","solutions":["Call CodeMirror(doc.copy()) or doc.linkedDoc() to get an independent copy for the second editor","Detach first: swapDoc a placeholder doc into the old editor before attaching elsewhere","Keep one editor per Doc and re-create the Doc from the saved value/text instead"],"exampleFix":"// before\notherEditor.swapDoc(sharedDoc); // sharedDoc still in use\n// after\notherEditor.swapDoc(CodeMirror.Doc(sharedDoc.getValue(), sharedDoc.modeOption));","handlingStrategy":"validation","validationCode":"function canAttach(doc) {\n  return doc && !doc.cm; // doc.cm is set while attached to an editor\n}\nif (!canAttach(doc)) doc = doc.copy(); // or CodeMirror.Doc(doc.getValue())","typeGuard":"function isFreeDoc(doc) {\n  return doc instanceof CodeMirror.Doc && doc.cm == null;\n}","tryCatchPattern":"try {\n  cm.swapDoc(doc);\n} catch (e) {\n  if (/already in use/.test(e.message)) {\n    cm.swapDoc(doc.linkedDoc({sharedHist: true}));\n  } else { throw e; }\n}","preventionTips":["One live editor per Doc; use linkedDoc()/copy() for shared views","Detach a doc (swapDoc a placeholder) before moving it between editors","Don't keep editor instances in caches with their docs if you plan to re-attach the docs elsewhere"],"tags":["codemirror","document","state"],"backgroundTag":"invalid-state-transition","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"}