Fission-AI/OpenSpec · error · Error
Invalid marker state in
Error message
Invalid marker state in ${filePath}. End marker appears before start marker. What it means
Thrown by updateFileWithMarkers when both start and end markers are present but the end marker's index precedes the start marker's. The managed block is malformed (markers swapped or duplicated), so a naive splice would delete the wrong region.
Solutions
- Edit the file named in the message to restore a proper START-then-END marker order
- Remove both markers and let the tooling re-insert the managed block
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at src/utils/file-system.ts:339 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of Fission-AI/OpenSpec@6926ccb18a (2026-08-25).
Data as JSON: /api/errors/51c5acebcc551305.
Report an issue: GitHub.
Appendix: source
Thrown at src/utils/file-system.ts:339
static async updateFileWithMarkers(
filePath: string,
content: string,
startMarker: string,
endMarker: string
): Promise<void> {
let existingContent = '';
if (await this.fileExists(filePath)) {
existingContent = await this.readFile(filePath);
const startIndex = findMarkerIndex(existingContent, startMarker);
const endIndex = startIndex !== -1
? findMarkerIndex(existingContent, endMarker, startIndex + startMarker.length)
: findMarkerIndex(existingContent, endMarker);
if (startIndex !== -1 && endIndex !== -1) {
if (endIndex < startIndex) {
throw new Error(
`Invalid marker state in ${filePath}. End marker appears before start marker.`
);
}
const before = existingContent.substring(0, startIndex);
const after = existingContent.substring(endIndex + endMarker.length);
existingContent = before + startMarker + '\n' + content + '\n' + endMarker + after;
} else if (startIndex === -1 && endIndex === -1) {
existingContent = startMarker + '\n' + content + '\n' + endMarker + '\n\n' + existingContent;
} else {
throw new Error(`Invalid marker state in ${filePath}. Found start: ${startIndex !== -1}, Found end: ${endIndex !== -1}`);
}
} else {
existingContent = startMarker + '\n' + content + '\n' + endMarker;
}
await this.writeFile(filePath, existingContent);
}View on GitHub (pinned to 6926ccb18a)