can1357/oh-my-pi · error · Error

Found "${start}" without a matching "${end}" in the shell co

Error message

Found "${start}" without a matching "${end}" in the shell config. The managed alias block is malformed; remove the stale marker line and rerun --alias.

What it means

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.

Source

Thrown at packages/coding-agent/src/cli/profile-alias.ts:315

		case "powershell":
		case "pwsh":
			body = [`function ${aliasName} {`, `    & ${command.powerShell} --profile=${profile} @args`, "}"].join("\n");
			break;
		default:
			body = [`${aliasName}() {`, `    command ${command.posix} --profile=${profile} "$@"`, "}"].join("\n");
			break;
	}
	return { block: `${start}\n${body}\n${end}`, command: profiledCommand };
}

function upsertBlock(content: string, aliasName: string, block: string): string {
	const start = `# >>> omp profile alias: ${aliasName} >>>`;
	const end = `# <<< omp profile alias: ${aliasName} <<<`;
	const startIndex = content.indexOf(start);
	if (startIndex !== -1) {
		const endIndex = content.indexOf(end, startIndex + start.length);
		if (endIndex === -1) {
			throw new Error(
				`Found "${start}" without a matching "${end}" in the shell config. ` +
					`The managed alias block is malformed; remove the stale marker line and rerun --alias.`,
			);
		}
		const afterEnd = endIndex + end.length;
		const prefix = content.slice(0, startIndex).replace(/[\t ]*\n?$/, "");
		const suffix = content.slice(afterEnd).replace(/^\n?/, "");
		return [prefix, block, suffix].filter(Boolean).join("\n\n").replace(/\n*$/, "\n");
	}
	const trimmed = content.replace(/\s*$/, "");
	return `${trimmed}${trimmed ? "\n\n" : ""}${block}\n`;
}

function readAliasConfigText(filePath: string): Promise<string> {
	return Bun.file(filePath).text();
}

export async function readProfileAliasConfigFile(

View on GitHub (pinned to 9690622007)

Solutions

  1. Open the shell config and delete the stale `# >>> omp profile alias: <name> >>>` line (and any orphaned alias lines below it)
  2. Rerun `omp --alias ...` so a fresh, complete block is installed
  3. Restore the missing `# <<< omp profile alias: <name> <<<` line if you want to keep the block and rerun instead

Example fix

// before (~/.zshrc)
# >>> omp profile alias: work >>>
alias work='omp --profile work'
// after (delete stale marker, then rerun --alias)
alias work='omp --profile work'  # or remove entirely and let the installer rewrite it
Defensive patterns

Strategy: try-catch

Validate before calling

const cfg = await Bun.file(shellConfigPath).text();
const start = `# >>> omp profile alias: ${aliasName} >>>`;
const end = `# <<< omp profile alias: ${aliasName} <<<`;
if (cfg.includes(start) && cfg.indexOf(end, cfg.indexOf(start) + start.length) === -1) {
  throw new Error(`Malformed omp alias block in ${shellConfigPath}; remove the stale marker first.`);
}

Try / catch

try {
  await installProfileAlias(options);
} catch (err) {
  if (err instanceof Error && err.message.includes("without a matching")) {
    // Repair: strip the orphan start marker line, then retry once
    let text = await Bun.file(configPath).text();
    text = text.split("\n").filter(l => !l.includes(`# >>> omp profile alias: ${aliasName} >>>`)).join("\n");
    await Bun.write(configPath, text);
    await installProfileAlias(options);
    return;
  }
  throw err;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/55305973f0fe83f7. Report an issue: GitHub.