kopia/kopia · error

one of --file, --token-file, --token-stdin or --token must…

Error message

one of --file, --token-file, --token-stdin or --token must be provided

What it means

The non-create path of `repository connect from-config` requires some way to locate the repository: either a connection file via --file or credentials via --token-file/--token-stdin/--token. Connect raised this fallback error because no such input was provided.

Solutions

  1. Add --token-file <path> (most common) with the token issued when the repository was created.
  2. Or supply the connection via --file <connect.config>, --token-stdin, or --token.
  3. Verify flag spelling; a mis-typed flag is silently ignored and triggers this error.

Example fix

// before
kopia repository connect from-config myrepo.config
// after
kopia repository connect from-config myrepo.config --token-file kopia.token
Defensive patterns

Strategy: validation

Validate before calling

flags := []bool{hasFile, hasTokenFile, hasTokenStdin, hasToken}
if !slices.ContainsFunc(flags, func(v bool) bool { return v }) {
  return errors.New("one of --file, --token-file, --token-stdin or --token is required")
}

Prevention

When it happens

Trigger: Running `kopia repository connect from-config` (without --create) with none of --file, --token-file, --token-stdin, or --token set; raised at cli/command_repository_connect_from_config.go:56.

Common situations: Users assuming the --config-file flag alone is enough to reconnect; automation scripts that dropped the token arguments; typos in flag names causing kopia to see them as unset.

Understand the failure class

Background: "--flag is required" and "must specify" CLI errors: how missing-required-flag validation works and how to fix it — this error's family across 20 libraries.

Related errors


AI-assisted analysis of kopia/kopia@82495e54b5 (2026-09-07). Data as JSON: /api/errors/f7e0a9599cb7b94e. Report an issue: GitHub.

Appendix: source

Thrown at cli/command_repository_connect_from_config.go:56

	}

	if c.connectFromConfigToken != "" {
		return c.connectToStorageFromConfigToken(ctx, c.connectFromConfigToken)
	}

	if c.connectFromTokenFile != "" {
		return c.connectToStorageFromStorageConfigFile(ctx)
	}

	if c.connectFromTokenStdin {
		return c.connectToStorageFromStorageConfigStdin(ctx)
	}

	if isCreate {
		return nil, errors.New("one of --token-file, --token-stdin or --token must be provided")
	}

	return nil, errors.New("one of --file, --token-file, --token-stdin or --token must be provided")
}

func (c *storageFromConfigFlags) connectToStorageFromConfigFile(ctx context.Context) (blob.Storage, error) {
	cfg, err := repo.LoadConfigFromFile(c.connectFromConfigFile)
	if err != nil {
		return nil, errors.Wrap(err, "unable to open config")
	}

	if cfg.Storage == nil {
		return nil, errors.New("connection file does not specify blob storage connection parameters, kopia server connections are not supported")
	}

	//nolint:wrapcheck
	return blob.NewStorage(ctx, *cfg.Storage, false)
}

func (c *storageFromConfigFlags) connectToStorageFromConfigToken(ctx context.Context, token string) (blob.Storage, error) {
	ci, pass, err := repo.DecodeToken(token)

View on GitHub (pinned to 82495e54b5)