Convert Shellerror::GenericError to named fields (#11230)

# Description

Replace `.to_string()` used in `GenericError` with `.into()` as
`.into()` seems more popular

Replace `Vec::new()` used in `GenericError` with `vec![]` as `vec![]`
seems more popular

(There are so, so many)
This commit is contained in:
Eric Hodel
2023-12-06 15:40:03 -08:00
committed by GitHub
parent b03f1efac4
commit a95a4505ef
160 changed files with 2975 additions and 3228 deletions

View File

@ -128,15 +128,14 @@ fn process(
// dbg!(&create_stmt);
conn.execute(&create_stmt, []).map_err(|err| {
ShellError::GenericError(
"Failed to open SQLite connection in memory from create".into(),
err.to_string(),
Some(Span::test_data()),
None,
Vec::new(),
)
})?;
conn.execute(&create_stmt, [])
.map_err(|err| ShellError::GenericError {
error: "Failed to open SQLite connection in memory from create".into(),
msg: err.to_string(),
span: Some(Span::test_data()),
help: None,
inner: vec![],
})?;
}
None => {
return Err(ShellError::MissingParameter {

View File

@ -112,15 +112,14 @@ impl Command for StorDelete {
};
// dbg!(&sql_stmt);
conn.execute(&sql_stmt, []).map_err(|err| {
ShellError::GenericError(
"Failed to open SQLite connection in memory from delete".into(),
err.to_string(),
Some(Span::test_data()),
None,
Vec::new(),
)
})?;
conn.execute(&sql_stmt, [])
.map_err(|err| ShellError::GenericError {
error: "Failed to open SQLite connection in memory from delete".into(),
msg: err.to_string(),
span: Some(Span::test_data()),
help: None,
inner: vec![],
})?;
}
}
// dbg!(db.clone());

View File

@ -70,14 +70,12 @@ impl Command for StorExport {
// This uses vacuum. I'm not really sure if this is the best way to do this.
// I also added backup in the sqlitedatabase impl. If we have problems, we could switch to that.
db.export_in_memory_database_to_file(&conn, file_name)
.map_err(|err| {
ShellError::GenericError(
"Failed to open SQLite connection in memory from export".into(),
err.to_string(),
Some(Span::test_data()),
None,
Vec::new(),
)
.map_err(|err| ShellError::GenericError {
error: "Failed to open SQLite connection in memory from export".into(),
msg: err.to_string(),
span: Some(Span::test_data()),
help: None,
inner: vec![],
})?;
}
// dbg!(db.clone());

View File

@ -68,14 +68,12 @@ impl Command for StorImport {
if let Ok(mut conn) = db.open_connection() {
db.restore_database_from_file(&mut conn, file_name)
.map_err(|err| {
ShellError::GenericError(
"Failed to open SQLite connection in memory from import".into(),
err.to_string(),
Some(Span::test_data()),
None,
Vec::new(),
)
.map_err(|err| ShellError::GenericError {
error: "Failed to open SQLite connection in memory from import".into(),
msg: err.to_string(),
span: Some(Span::test_data()),
help: None,
inner: vec![],
})?;
}
// dbg!(db.clone());

View File

@ -119,15 +119,14 @@ impl Command for StorInsert {
// dbg!(&create_stmt);
conn.execute(&create_stmt, []).map_err(|err| {
ShellError::GenericError(
"Failed to open SQLite connection in memory from insert".into(),
err.to_string(),
Some(Span::test_data()),
None,
Vec::new(),
)
})?;
conn.execute(&create_stmt, [])
.map_err(|err| ShellError::GenericError {
error: "Failed to open SQLite connection in memory from insert".into(),
msg: err.to_string(),
span: Some(Span::test_data()),
help: None,
inner: vec![],
})?;
}
None => {
return Err(ShellError::MissingParameter {

View File

@ -49,15 +49,14 @@ impl Command for StorReset {
let db = Box::new(SQLiteDatabase::new(std::path::Path::new(MEMORY_DB), None));
if let Ok(conn) = db.open_connection() {
db.drop_all_tables(&conn).map_err(|err| {
ShellError::GenericError(
"Failed to open SQLite connection in memory from reset".into(),
err.to_string(),
Some(Span::test_data()),
None,
Vec::new(),
)
})?;
db.drop_all_tables(&conn)
.map_err(|err| ShellError::GenericError {
error: "Failed to open SQLite connection in memory from reset".into(),
msg: err.to_string(),
span: Some(Span::test_data()),
help: None,
inner: vec![],
})?;
}
// dbg!(db.clone());
Ok(Value::custom_value(db, span).into_pipeline_data())

View File

@ -131,15 +131,14 @@ impl Command for StorUpdate {
}
// dbg!(&update_stmt);
conn.execute(&update_stmt, []).map_err(|err| {
ShellError::GenericError(
"Failed to open SQLite connection in memory from update".into(),
err.to_string(),
Some(Span::test_data()),
None,
Vec::new(),
)
})?;
conn.execute(&update_stmt, [])
.map_err(|err| ShellError::GenericError {
error: "Failed to open SQLite connection in memory from update".into(),
msg: err.to_string(),
span: Some(Span::test_data()),
help: None,
inner: vec![],
})?;
}
None => {
return Err(ShellError::MissingParameter {