Bladeren bron

fix: Show correct default path in signer error messages (#7849)

Fixes the problem with Solana CLI when configuration contains an invalid `keypair_path`: error messages suggest creating new keypairs at the misconfigured location instead of the user's actual default directory. This leads to confusion and keypairs being created in wrong locations.
Modified error message generation in `efaultSigner::path()` to always suggest the system default path based on the user's actual home directory, regardless of any misconfigured paths in config files.
Swarna 2 maanden geleden
bovenliggende
commit
7c3e9e745f
6 gewijzigde bestanden met toevoegingen van 21 en 2 verwijderingen
  1. 2 0
      Cargo.lock
  2. 1 0
      clap-utils/Cargo.toml
  3. 8 1
      clap-utils/src/keypair.rs
  4. 1 0
      clap-v3-utils/Cargo.toml
  5. 8 1
      clap-v3-utils/src/keypair.rs
  6. 1 0
      programs/sbf/Cargo.lock

+ 2 - 0
Cargo.lock

@@ -7650,6 +7650,7 @@ dependencies = [
  "assert_matches",
  "chrono",
  "clap 2.33.3",
+ "dirs-next",
  "rpassword",
  "solana-clock",
  "solana-cluster-type",
@@ -7680,6 +7681,7 @@ dependencies = [
  "assert_matches",
  "chrono",
  "clap 3.2.23",
+ "dirs-next",
  "rpassword",
  "solana-clock",
  "solana-cluster-type",

+ 1 - 0
clap-utils/Cargo.toml

@@ -18,6 +18,7 @@ name = "solana_clap_utils"
 [dependencies]
 chrono = { workspace = true, features = ["default"] }
 clap = "2.33.0"
+dirs-next = { workspace = true }
 rpassword = { workspace = true }
 solana-clock = { workspace = true }
 solana-cluster-type = { workspace = true }

+ 8 - 1
clap-utils/src/keypair.rs

@@ -175,10 +175,17 @@ impl DefaultSigner {
                     }
                 })
                 .map_err(|_| {
+                    // Use the system default path in the error message instead of the configured path
+                    let default_path = dirs_next::home_dir()
+                        .map(|mut path| {
+                            path.extend([".config", "solana", "id.json"]);
+                            path.to_str().unwrap_or(&self.path).to_string()
+                        })
+                        .unwrap_or_else(|| self.path.clone());
                     std::io::Error::other(format!(
                         "No default signer found, run \"solana-keygen new -o {}\" to create a new \
                          one",
-                        self.path
+                        default_path
                     ))
                 })?;
             *self.is_path_checked.borrow_mut() = true;

+ 1 - 0
clap-v3-utils/Cargo.toml

@@ -22,6 +22,7 @@ elgamal = ["dep:solana-zk-sdk"]
 [dependencies]
 chrono = { workspace = true, features = ["default"] }
 clap = { version = "3.2.23", features = ["cargo"] }
+dirs-next = { workspace = true }
 rpassword = { workspace = true }
 solana-clock = { workspace = true }
 solana-cluster-type = { workspace = true }

+ 8 - 1
clap-v3-utils/src/keypair.rs

@@ -171,10 +171,17 @@ impl DefaultSigner {
                     }
                 })
                 .map_err(|_| {
+                    // Use the system default path in the error message instead of the configured path
+                    let default_path = dirs_next::home_dir()
+                        .map(|mut path| {
+                            path.extend([".config", "solana", "id.json"]);
+                            path.to_str().unwrap_or(&self.path).to_string()
+                        })
+                        .unwrap_or_else(|| self.path.clone());
                     std::io::Error::other(format!(
                         "No default signer found, run \"solana-keygen new -o {}\" to create a new \
                          one",
-                        self.path
+                        default_path
                     ))
                 })?;
             *self.is_path_checked.borrow_mut() = true;

+ 1 - 0
programs/sbf/Cargo.lock

@@ -6156,6 +6156,7 @@ version = "3.1.0"
 dependencies = [
  "chrono",
  "clap",
+ "dirs-next",
  "rpassword",
  "solana-clock",
  "solana-cluster-type",