{"record":{"id":"51c5acebcc551305","repo":"Fission-AI/OpenSpec","slug":"invalid-marker-state-in-filepath-end-marker-ap","errorCode":null,"errorMessage":"Invalid marker state in ${filePath}. End marker appears before start marker.","messagePattern":"Invalid marker state in (.+?)\\. End marker appears before start marker\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/utils/file-system.ts","lineNumber":339,"sourceCode":"  static async updateFileWithMarkers(\n    filePath: string,\n    content: string,\n    startMarker: string,\n    endMarker: string\n  ): Promise<void> {\n    let existingContent = '';\n    \n    if (await this.fileExists(filePath)) {\n      existingContent = await this.readFile(filePath);\n      \n      const startIndex = findMarkerIndex(existingContent, startMarker);\n      const endIndex = startIndex !== -1\n        ? findMarkerIndex(existingContent, endMarker, startIndex + startMarker.length)\n        : findMarkerIndex(existingContent, endMarker);\n\n      if (startIndex !== -1 && endIndex !== -1) {\n        if (endIndex < startIndex) {\n          throw new Error(\n            `Invalid marker state in ${filePath}. End marker appears before start marker.`\n          );\n        }\n\n        const before = existingContent.substring(0, startIndex);\n        const after = existingContent.substring(endIndex + endMarker.length);\n        existingContent = before + startMarker + '\\n' + content + '\\n' + endMarker + after;\n      } else if (startIndex === -1 && endIndex === -1) {\n        existingContent = startMarker + '\\n' + content + '\\n' + endMarker + '\\n\\n' + existingContent;\n      } else {\n        throw new Error(`Invalid marker state in ${filePath}. Found start: ${startIndex !== -1}, Found end: ${endIndex !== -1}`);\n      }\n    } else {\n      existingContent = startMarker + '\\n' + content + '\\n' + endMarker;\n    }\n    \n    await this.writeFile(filePath, existingContent);\n  }","sourceCodeStart":321,"sourceCodeEnd":357,"githubUrl":"https://github.com/Fission-AI/OpenSpec/blob/6926ccb18afa4ff621112813e9968334576ee11a/src/utils/file-system.ts#L321-L357","documentation":"Error \"Invalid marker state in ${filePath}. End marker appears before start marker.\" thrown in Fission-AI/OpenSpec.","triggerScenarios":"Thrown at src/utils/file-system.ts:339 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"6926ccb18afa4ff621112813e9968334576ee11a","analyzedAt":"2026-08-25T12:29:45.729Z","schemaVersion":2},"datasetVersion":"2026-08-25T16:17:27.014Z"}