{"record":{"id":"55305973f0fe83f7","repo":"can1357/oh-my-pi","slug":"found-start-without-a-matching-end-in-th","errorCode":null,"errorMessage":"Found \"${start}\" without a matching \"${end}\" in the shell config. The managed alias block is malformed; remove the stale marker line and rerun --alias.","messagePattern":"Found \"(.+?)\" without a matching \"(.+?)\" in the shell config\\. The managed alias block is malformed; remove the stale marker line and rerun --alias\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/cli/profile-alias.ts","lineNumber":315,"sourceCode":"\t\tcase \"powershell\":\n\t\tcase \"pwsh\":\n\t\t\tbody = [`function ${aliasName} {`, `    & ${command.powerShell} --profile=${profile} @args`, \"}\"].join(\"\\n\");\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tbody = [`${aliasName}() {`, `    command ${command.posix} --profile=${profile} \"$@\"`, \"}\"].join(\"\\n\");\n\t\t\tbreak;\n\t}\n\treturn { block: `${start}\\n${body}\\n${end}`, command: profiledCommand };\n}\n\nfunction upsertBlock(content: string, aliasName: string, block: string): string {\n\tconst start = `# >>> omp profile alias: ${aliasName} >>>`;\n\tconst end = `# <<< omp profile alias: ${aliasName} <<<`;\n\tconst startIndex = content.indexOf(start);\n\tif (startIndex !== -1) {\n\t\tconst endIndex = content.indexOf(end, startIndex + start.length);\n\t\tif (endIndex === -1) {\n\t\t\tthrow new Error(\n\t\t\t\t`Found \"${start}\" without a matching \"${end}\" in the shell config. ` +\n\t\t\t\t\t`The managed alias block is malformed; remove the stale marker line and rerun --alias.`,\n\t\t\t);\n\t\t}\n\t\tconst afterEnd = endIndex + end.length;\n\t\tconst prefix = content.slice(0, startIndex).replace(/[\\t ]*\\n?$/, \"\");\n\t\tconst suffix = content.slice(afterEnd).replace(/^\\n?/, \"\");\n\t\treturn [prefix, block, suffix].filter(Boolean).join(\"\\n\\n\").replace(/\\n*$/, \"\\n\");\n\t}\n\tconst trimmed = content.replace(/\\s*$/, \"\");\n\treturn `${trimmed}${trimmed ? \"\\n\\n\" : \"\"}${block}\\n`;\n}\n\nfunction readAliasConfigText(filePath: string): Promise<string> {\n\treturn Bun.file(filePath).text();\n}\n\nexport async function readProfileAliasConfigFile(","sourceCodeStart":297,"sourceCodeEnd":333,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/cli/profile-alias.ts#L297-L333","documentation":"upsertBlock found the start marker `# >>> omp profile alias: <name> >>>` in the shell config but no matching end marker `# <<< ... <<<`. The managed block is malformed, and blindly appending would corrupt the config, so the tool refuses and asks for manual cleanup. This is a data-integrity guard over hand-edited shell rc files.","triggerScenarios":"Re-running `omp --alias` for an alias whose previously installed block in ~/.bashrc, ~/.zshrc, etc. had its end-marker line deleted or mangled by manual editing, a truncating editor, or a merge conflict that removed only the closing line.","commonSituations":"Hand-editing the rc file and deleting the `<<<` comment thinking it was noise; git merge conflicts resolving to keep only the block header; partial file writes/interruptions during a prior install.","solutions":["Open the shell config and delete the stale `# >>> omp profile alias: <name> >>>` line (and any orphaned alias lines below it)","Rerun `omp --alias ...` so a fresh, complete block is installed","Restore the missing `# <<< omp profile alias: <name> <<<` line if you want to keep the block and rerun instead"],"exampleFix":"// before (~/.zshrc)\n# >>> omp profile alias: work >>>\nalias work='omp --profile work'\n// after (delete stale marker, then rerun --alias)\nalias work='omp --profile work'  # or remove entirely and let the installer rewrite it","handlingStrategy":"try-catch","validationCode":"const cfg = await Bun.file(shellConfigPath).text();\nconst start = `# >>> omp profile alias: ${aliasName} >>>`;\nconst end = `# <<< omp profile alias: ${aliasName} <<<`;\nif (cfg.includes(start) && cfg.indexOf(end, cfg.indexOf(start) + start.length) === -1) {\n  throw new Error(`Malformed omp alias block in ${shellConfigPath}; remove the stale marker first.`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await installProfileAlias(options);\n} catch (err) {\n  if (err instanceof Error && err.message.includes(\"without a matching\")) {\n    // Repair: strip the orphan start marker line, then retry once\n    let text = await Bun.file(configPath).text();\n    text = text.split(\"\\n\").filter(l => !l.includes(`# >>> omp profile alias: ${aliasName} >>>`)).join(\"\\n\");\n    await Bun.write(configPath, text);\n    await installProfileAlias(options);\n    return;\n  }\n  throw err;\n}","preventionTips":["Never hand-edit the marker lines `# >>> omp profile alias: ... >>>` / `<<< ... <<<` in your rc file","Resolve merge conflicts by keeping both marker lines of the managed block, not just one","Back up your shell config before running --alias, and re-run --alias rather than manually deleting partial blocks"],"tags":["cli","shell-config","corruption","marker"],"backgroundTag":"malformed-managed-block","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}