{"record":{"id":"05431c9c8e95593b","repo":"ipfs/kubo","slug":"keystore-name-for-backing-up-old-key-must-be-provi","errorCode":null,"errorMessage":"keystore name for backing up old key must be provided","messagePattern":"keystore name for backing up old key must be provided","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/commands/keystore.go","lineNumber":762,"sourceCode":"\n    export IPFS_PATH=/path/to/ipfsrepo\n`,\n\t},\n\tArguments: []cmds.Argument{},\n\tOptions: []cmds.Option{\n\t\tcmds.StringOption(oldKeyOptionName, \"o\", \"Keystore name to use for backing up your existing identity\"),\n\t\tcmds.StringOption(keyStoreTypeOptionName, \"t\", \"type of the key to create: rsa, ed25519, secp256k1\").WithDefault(keyStoreAlgorithmDefault),\n\t\tcmds.IntOption(keyStoreSizeOptionName, \"s\", \"size of the key to generate\"),\n\t},\n\tNoRemote: true,\n\tPreRun:   DaemonNotRunning,\n\tRun: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {\n\t\tcctx := env.(*oldcmds.Context)\n\t\tnBitsForKeypair, nBitsGiven := req.Options[keyStoreSizeOptionName].(int)\n\t\talgorithm, _ := req.Options[keyStoreTypeOptionName].(string)\n\t\toldKey, ok := req.Options[oldKeyOptionName].(string)\n\t\tif !ok {\n\t\t\treturn fmt.Errorf(\"keystore name for backing up old key must be provided\")\n\t\t}\n\t\tif oldKey == \"self\" {\n\t\t\treturn fmt.Errorf(\"keystore name for back up cannot be named 'self'\")\n\t\t}\n\t\treturn doRotate(os.Stdout, cctx.ConfigRoot, oldKey, algorithm, nBitsForKeypair, nBitsGiven)\n\t},\n}\n\nfunc doRotate(out io.Writer, repoRoot string, oldKey string, algorithm string, nBitsForKeypair int, nBitsGiven bool) error {\n\t// Open repo\n\trepo, err := fsrepo.Open(repoRoot)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"opening repo (%v)\", err)\n\t}\n\tdefer repo.Close()\n\n\t// Read config file from repo\n\tcfg, err := repo.Config()","sourceCodeStart":744,"sourceCodeEnd":780,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/commands/keystore.go#L744-L780","documentation":"The `ipfs key rotate` command requires the `--old-key` option naming the keystore entry under which the node's current `self` identity key will be backed up before generating a new identity. This error is returned from the command's Run function when the option was not supplied at all (the type assertion to string fails). The rotate operation refuses to destroy the old identity without a safe backup location.","triggerScenarios":"Running `ipfs key rotate` without the `--old-key <name>` flag; calling the command programmatically via cmds.Request with the oldKeyOptionName option omitted or set to a non-string value.","commonSituations":"Users copying an older rotate command invocation that predates the --old-key requirement; scripts or automation that forgot the flag; mistyping the flag name so the option is never set.","solutions":["Re-run the command with `--old-key <name>` (e.g. `ipfs key rotate --old-key=old-self`)","Pick a keystore name that is not 'self' and does not collide with an existing key you care about","Check `ipfs key list` afterwards to confirm the old identity was backed up under the given name"],"exampleFix":"// before\nipfs key rotate -o ed25519\n// after\nipfs key rotate -o ed25519 --old-key=old-self","handlingStrategy":"validation","validationCode":"oldKey, ok := req.Options[oldKeyOptionName].(string)\nif !ok || oldKey == \"\" {\n    return errors.New(\"--old-key is required for key rotate\")\n}","typeGuard":"func hasOldKey(opts map[string]interface{}) (string, bool) {\n    v, ok := opts[oldKeyOptionName].(string)\n    return v, ok && v != \"\"\n}","tryCatchPattern":"if err := doRotate(os.Stdout, cfgRoot, oldKey, alg, bits, bitsGiven); err != nil {\n    if strings.Contains(err.Error(), \"must be provided\") {\n        // prompt user / default the backup name\n    }\n}","preventionTips":["Always pass --old-key when using `ipfs key rotate`","Wrap rotate in a script that asserts the flag is present before executing","Read `ipfs key rotate --help` before scripted use"],"tags":["cli","keystore","missing-argument"],"backgroundTag":"missing-required-argument","analyzedSha":"329838acdfafae224582930457efe80aa217afc0","analyzedAt":"2026-09-03T18:30:52.135Z","contentChangedAt":"2026-09-03T18:30:52.135Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}