tirth8205/code-review-graph · error · ValueError

Alias '{effective_alias}' is already in use by {existing.pat

Error message

Alias '{effective_alias}' is already in use by {existing.path}

What it means

When adding a repo to the daemon config, aliases must be unique. If the computed or supplied alias already maps to a different configured repo, add_repo_to_config raises ValueError instead of silently shadowing it. Note: a duplicate PATH is not an error — it logs a warning and returns the existing config unchanged.

Source

Thrown at code_review_graph/daemon.py:346

    has_repo_marker = (
        (resolved / ".git").exists()
        or (resolved / ".svn").exists()
        or (resolved / ".code-review-graph").exists()
    )
    if not has_repo_marker:
        raise ValueError(f"No .git, .svn, or .code-review-graph directory in {resolved}")

    effective_alias = alias or resolved.name

    config = load_config(config_path)

    # Check for duplicate path or alias
    for existing in config.repos:
        if existing.path == str(resolved):
            logger.warning("Repo %s is already configured — skipping", resolved)
            return config
        if existing.alias == effective_alias:
            raise ValueError(f"Alias '{effective_alias}' is already in use by {existing.path}")

    config.repos.append(WatchRepo(path=str(resolved), alias=effective_alias))
    save_config(config, config_path)
    return config


def remove_repo_from_config(
    path_or_alias: str,
    config_path: Path | None = None,
) -> DaemonConfig:
    """Remove a repository from the daemon config by path or alias.

    Args:
        path_or_alias: Either the absolute/relative repo path or its alias.
        config_path:   Explicit config file path.  Falls back to :func:`default_config_path`.

    Returns:
        The updated :class:`DaemonConfig`.

View on GitHub (pinned to b58668751a)

Solutions

  1. Pass a distinct --alias: `code-review-graph daemon add ~/work/api --alias work-api`
  2. Or remove/rename the existing repo entry that owns the alias (edit the daemon config TOML or use the remove command), then retry
  3. When scripting, derive aliases from the full path (not basename) to guarantee uniqueness

Example fix

# before
$ code-review-graph daemon add ~/work/api
ValueError: Alias 'api' is already in use by /home/me/src/api

# after
$ code-review-graph daemon add ~/work/api --alias work-api
Defensive patterns

Strategy: validation

Validate before calling

from code_review_graph.daemon import load_config, default_config_path

cfg = load_config(default_config_path())
resolved = str(Path(repo_path).expanduser().resolve())
alias = my_alias or Path(resolved).name
taken = {r.alias for r in cfg.repos}
assert alias not in taken, f"alias {alias!r} already used; try {alias}-2"

Type guard

def is_alias_free(cfg, alias: str) -> bool:
    return all(r.alias != alias for r in cfg.repos)

Try / catch

try:
    add_repo_to_config(repo_path, alias)
except ValueError as e:
    if "already in use" in str(e):
        add_repo_to_config(repo_path, f"{alias or Path(repo_path).name}-{Path(repo_path).parent.name}")
    else:
        raise

Prevention

When it happens

Trigger: Calling daemon add with an --alias that matches another repo's alias, or adding two repos whose directory basenames are identical (the alias defaults to resolved.name), e.g. two checkouts both named 'api'.

Common situations: Multiple worktrees/clones of the same project in different locations, monorepos with same-named subdirectories, or reusing a friendly alias like 'main' across machines/copies.

Related errors


AI-assisted analysis of tirth8205/code-review-graph@b58668751a (2026-08-28). Data as JSON: /api/errors/4c391236c8fd75a1. Report an issue: GitHub.