replicatedhq / replicatedhq/replicated

InitCache should not be called for completion commands

Open Beginner friendly
#535 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

agent-working
Dominant language
Go
Stars
36
Forks
25
Avg merge
9h 27m
Merged PRs (30d)
3

Description

I notice that my nix build of replicated now breaks as it tries to generate the completions.

The error can be replicated like so:

HOME=/invalid replicated completion zsh
panic: failed to save cache: failed to create cache directory: mkdir /invalid: permission denied

goroutine 1 [running]:
github.com/replicatedhq/replicated/cli/cmd.init.0()
	/mnt/cli/cmd/root.go:48 +0xe5

For now, I am setting HOME=/tmp during the build.

Whole nix script
{ stdenv
, lib
, fetchurl
, installShellFiles
#, autoPatchelfHook
}:

stdenv.mkDerivation rec {
  pname = "replicated";
  version = "0.101.0";

  src = fetchurl {
    url = "https://github.com/replicatedhq/replicated/releases/download/v${version}/replicated_${version}_linux_amd64.tar.gz";
    hash = "sha256-5i4ri2pBfpbqlMd6v5JVGwsnkN0cvoa+ul04K4xCfJk=";
  };

  nativeBuildInputs = [
    # autoPatchelfHook
    installShellFiles
  ];

  buildInputs = [
  ];

  sourceRoot = ".";

  installPhase = ''
    runHook preInstall
    install -m755 -D replicated $out/bin/replicated
    # Because cache is initialized and tries to write to HOME
    export HOME=/tmp
    installShellCompletion --cmd replicated \
      --bash <($out/bin/replicated completion bash) \
      --fish <($out/bin/replicated completion fish) \
      --zsh <($out/bin/replicated completion zsh)
    runHook postInstall
  '';

  meta = with lib; {
    homepage = "https://replicated.com";
    description = "Replicated CLI";
    platforms = platforms.linux;
  };
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at cli/cmd/root.go:48 and trace the InitCache call reached when running the completion commands. Reproduce the failure with HOME=/invalid replicated completion zsh, then verify bash, fish, and zsh completion generation succeeds without trying to create the cache directory.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
cli
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.