fix: resolve compilation errors by adding missing imports and fixing Result types
- Import `anyhow`, `clap::Command`, `log::debug`, and I/O traits - Fix all `Result` return types to include error type `anyhow::Error` - Replace `anyhow::anyhow!` with `anyhow!` macro calls - Fix transaction handling in `mode_save` - Add missing trait imports for I/O operations and string parsing Co-authored-by: aider (openai/andrew/openrouter/qwen/qwen3-coder) <aider@aider.chat>
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
use anyhow::{anyhow, Result};
|
||||
use clap::Command;
|
||||
use log::debug;
|
||||
use std::io::{Read, Write, IsTerminal};
|
||||
|
||||
fn validate_save_args(cmd: &mut Command, ids: &Vec<i64>) {
|
||||
if !ids.is_empty() {
|
||||
cmd.error(
|
||||
@@ -73,7 +78,7 @@ fn create_and_log_item(
|
||||
args: &crate::Args,
|
||||
tags: &Vec<String>,
|
||||
compression_type: &crate::compression_engine::CompressionType,
|
||||
) -> Result<crate::db::Item> {
|
||||
) -> Result<crate::db::Item, anyhow::Error> {
|
||||
let mut item = crate::db::Item {
|
||||
id: None,
|
||||
ts: chrono::Utc::now(),
|
||||
@@ -116,7 +121,7 @@ fn setup_item_metadata(
|
||||
args: &crate::Args,
|
||||
item: &crate::db::Item,
|
||||
tags: &Vec<String>,
|
||||
) -> Result<()> {
|
||||
) -> Result<(), anyhow::Error> {
|
||||
crate::db::set_item_tags(conn, item.clone(), tags)?;
|
||||
Ok(())
|
||||
}
|
||||
@@ -143,7 +148,7 @@ fn process_input_stream(
|
||||
data_path: &std::path::PathBuf,
|
||||
item_id: i64,
|
||||
meta_plugins: &mut Vec<Box<dyn crate::meta_plugin::MetaPlugin>>,
|
||||
) -> Result<(Box<dyn std::io::Write>, crate::db::Item)> {
|
||||
) -> Result<(Box<dyn std::io::Write>, crate::db::Item), anyhow::Error> {
|
||||
let mut item = crate::db::Item {
|
||||
id: Some(item_id),
|
||||
ts: chrono::Utc::now(),
|
||||
@@ -161,10 +166,7 @@ fn process_input_stream(
|
||||
let mut item_out: Box<dyn std::io::Write> =
|
||||
compression_engine
|
||||
.create(item_path.clone())
|
||||
.context(anyhow::anyhow!(
|
||||
"Unable to write file {:?}",
|
||||
item_path
|
||||
))?;
|
||||
.map_err(|e| anyhow!("Unable to write file {:?}: {}", item_path, e))?;
|
||||
|
||||
debug!("MAIN: Starting IO loop");
|
||||
loop {
|
||||
@@ -200,7 +202,7 @@ fn finalize_meta_plugins(
|
||||
conn: &rusqlite::Connection,
|
||||
meta_plugins: &mut Vec<Box<dyn crate::meta_plugin::MetaPlugin>>,
|
||||
item: &crate::db::Item,
|
||||
) -> Result<()> {
|
||||
) -> Result<(), anyhow::Error> {
|
||||
for meta_plugin in meta_plugins.iter_mut() {
|
||||
let meta_name = meta_plugin.meta_name();
|
||||
|
||||
@@ -225,7 +227,7 @@ pub fn mode_save(
|
||||
tags: &mut Vec<String>,
|
||||
conn: &mut rusqlite::Connection,
|
||||
data_path: std::path::PathBuf,
|
||||
) -> Result<()> {
|
||||
) -> Result<(), anyhow::Error> {
|
||||
validate_save_args(cmd, ids);
|
||||
initialize_tags(tags);
|
||||
|
||||
@@ -238,7 +240,7 @@ pub fn mode_save(
|
||||
let tx = conn.transaction()?;
|
||||
|
||||
let item_meta = collect_item_meta(args);
|
||||
let item_id = item.id.ok_or_else(|| anyhow::anyhow!("Item missing ID"))?;
|
||||
let item_id = item.id.ok_or_else(|| anyhow!("Item missing ID"))?;
|
||||
|
||||
for kv in item_meta.iter() {
|
||||
let meta = crate::db::Meta {
|
||||
@@ -259,7 +261,7 @@ pub fn mode_save(
|
||||
item.size = processed_item.size;
|
||||
item.compression = compression_type.to_string();
|
||||
|
||||
finalize_meta_plugins(&tx, &mut meta_plugins, &item)?;
|
||||
finalize_meta_plugins(&mut tx.into_inner(), &mut meta_plugins, &item)?;
|
||||
crate::db::update_item(&tx, item.clone())?;
|
||||
|
||||
// Commit the transaction
|
||||
|
||||
Reference in New Issue
Block a user