Skip to content

Commit 5577fc6

Browse files
Address PR feedback
1 parent 6c2f6b1 commit 5577fc6

File tree

1 file changed

+22
-38
lines changed
  • cmd/soroban-cli/src/commands/contract

1 file changed

+22
-38
lines changed

cmd/soroban-cli/src/commands/contract/init.rs

+22-38
Original file line numberDiff line numberDiff line change
@@ -60,25 +60,25 @@ pub enum Error {
6060
#[error("{0}: {1}")]
6161
Io(String, io::Error),
6262

63-
#[error("Io Error:")]
63+
#[error("io error:")]
6464
StdIo(#[from] io::Error),
6565

6666
#[error("{0}: {1}")]
6767
Json(String, JsonError),
6868

69-
#[error("Failed to parse toml file: {0}")]
69+
#[error("failed to parse toml file: {0}")]
7070
TomlParse(#[from] TomlError),
7171

72-
#[error("Failed to convert bytes to string: {0}")]
72+
#[error("failed to convert bytes to string: {0}")]
7373
ConvertBytesToString(#[from] str::Utf8Error),
7474

75-
#[error("Error preparing fetch repository: {0}")]
75+
#[error("preparing fetch repository: {0}")]
7676
PrepareFetch(Box<clone::Error>),
7777

78-
#[error("Failed to fetch repository: {0}")]
78+
#[error("failed to fetch repository: {0}")]
7979
Fetch(Box<clone::fetch::Error>),
8080

81-
#[error("Failed to checkout main worktree: {0}")]
81+
#[error("failed to checkout main worktree: {0}")]
8282
Checkout(#[from] clone::checkout::main_worktree::Error),
8383
}
8484

@@ -119,12 +119,8 @@ impl Runner {
119119

120120
if !self.args.frontend_template.is_empty() {
121121
// create a temp dir for the template repo
122-
let fe_template_dir = tempfile::tempdir().map_err(|e| {
123-
Error::Io(
124-
"Error creating temp dir for frontend template".to_string(),
125-
e,
126-
)
127-
})?;
122+
let fe_template_dir = tempfile::tempdir()
123+
.map_err(|e| Error::Io("creating temp dir for frontend template".to_string(), e))?;
128124

129125
// clone the template repo into the temp dir
130126
Self::clone_repo(&self.args.frontend_template, fe_template_dir.path())?;
@@ -136,12 +132,8 @@ impl Runner {
136132
// if there are --with-example flags, include the example contracts
137133
if self.include_example_contracts() {
138134
// create an examples temp dir
139-
let examples_dir = tempfile::tempdir().map_err(|e| {
140-
Error::Io(
141-
"Error creating temp dir for soroban-examples".to_string(),
142-
e,
143-
)
144-
})?;
135+
let examples_dir = tempfile::tempdir()
136+
.map_err(|e| Error::Io("creating temp dir for soroban-examples".to_string(), e))?;
145137

146138
// clone the soroban-examples repo into the temp dir
147139
Self::clone_repo(SOROBAN_EXAMPLES_URL, examples_dir.path())?;
@@ -206,11 +198,11 @@ impl Runner {
206198
"target",
207199
"Cargo.lock",
208200
];
209-
for entry in read_dir(from)
210-
.map_err(|e| Error::Io(format!("Error reading directory: {from:?}"), e))?
201+
for entry in
202+
read_dir(from).map_err(|e| Error::Io(format!("reading directory: {from:?}"), e))?
211203
{
212-
let entry = entry
213-
.map_err(|e| Error::Io(format!("Error reading entry in directory {from:?}",), e))?;
204+
let entry =
205+
entry.map_err(|e| Error::Io(format!("reading entry in directory {from:?}",), e))?;
214206
let path = entry.path();
215207
let entry_name = entry.file_name().to_string_lossy().to_string();
216208
let new_path = to.join(&entry_name);
@@ -248,7 +240,7 @@ impl Runner {
248240
copy(&path, &new_path).map_err(|e| {
249241
Error::Io(
250242
format!(
251-
"Error copying from {:?} to {:?}",
243+
"copying from {:?} to {:?}",
252244
path.to_string_lossy(),
253245
new_path
254246
),
@@ -365,7 +357,7 @@ impl Runner {
365357
name.to_owned()
366358
} else {
367359
let current_dir = env::current_dir()
368-
.map_err(|e| Error::Io("Error getting current dir from env".to_string(), e))?;
360+
.map_err(|e| Error::Io("getting current dir from env".to_string(), e))?;
369361
let file_name = current_dir
370362
.file_name()
371363
.unwrap_or(OsStr::new("soroban-astro-template"))
@@ -386,20 +378,13 @@ impl Runner {
386378
let file_contents = Self::read_to_string(&file_path)?;
387379

388380
let mut doc: JsonValue = from_str(&file_contents).map_err(|e| {
389-
Error::Json(
390-
format!("Error parsing {file_name} file in: {project_path:?}"),
391-
e,
392-
)
381+
Error::Json(format!("parsing {file_name} file in: {project_path:?}"), e)
393382
})?;
394383

395384
doc["name"] = json!(package_name.to_string_lossy());
396385

397-
let formatted_json = to_string_pretty(&doc).map_err(|e| {
398-
Error::Json(
399-
"Error calling to_string_pretty for package.json".to_string(),
400-
e,
401-
)
402-
})?;
386+
let formatted_json = to_string_pretty(&doc)
387+
.map_err(|e| Error::Json("calling to_string_pretty for package.json".to_string(), e))?;
403388

404389
Self::write(&file_path, &formatted_json)?;
405390

@@ -442,16 +427,15 @@ impl Runner {
442427
}
443428

444429
fn create_dir_all(path: &Path) -> Result<(), Error> {
445-
create_dir_all(path)
446-
.map_err(|e| Error::Io(format!("Error creating directory: {path:?}"), e))
430+
create_dir_all(path).map_err(|e| Error::Io(format!("creating directory: {path:?}"), e))
447431
}
448432

449433
fn write(path: &Path, contents: &str) -> Result<(), Error> {
450-
write(path, contents).map_err(|e| Error::Io(format!("Error writing file: {path:?}"), e))
434+
write(path, contents).map_err(|e| Error::Io(format!("writing file: {path:?}"), e))
451435
}
452436

453437
fn read_to_string(path: &Path) -> Result<String, Error> {
454-
read_to_string(path).map_err(|e| Error::Io(format!("Error reading file: {path:?}"), e))
438+
read_to_string(path).map_err(|e| Error::Io(format!("reading file: {path:?}"), e))
455439
}
456440
}
457441

0 commit comments

Comments
 (0)