···11use std::{process::Command, thread::spawn};
2233-use color_eyre::eyre::Result;
33+use color_eyre::eyre::{Context, Result};
44use crossterm::event::KeyEvent;
55use ratatui::layout::Rect;
66use serde::{Deserialize, Serialize};
···192192 // once we get out of the edit, we need to update the zettel for this
193193 // path and then update the db and the kasten for this stuff
194194195195- self.kh.write().await.process_path(&path).await?;
195195+ self.kh
196196+ .write()
197197+ .await
198198+ .process_path(&path)
199199+ .await
200200+ .with_context(|| {
201201+ format!(
202202+ "Failed to process the path
203203+ for this zettel: {}",
204204+ path.display()
205205+ )
206206+ })?;
207207+208208+ debug!("successfully processed path: {}", path.display());
196209197210 self.signal_tx.send(Signal::ClosedZettel)?;
198211
+12-9
src/tui/components/zk/mod.rs
···11use async_trait::async_trait;
22-use color_eyre::eyre::{ContextCompat, Result};
22+use color_eyre::eyre::{Context as _, ContextCompat, Result};
33use crossterm::event::KeyEvent;
44use dto::{QueryOrder, TagEntity, ZettelColumns, ZettelEntity};
55use ratatui::{prelude::*, widgets::ListState};
···243243 let mut kt = self.kh.write().await;
244244245245 // we create the zettel with the query as the
246246- let z = Zettel::new(self.search.query(), &mut kt).await?;
246246+ let z = Zettel::new(self.search.query(), &mut kt)
247247+ .await
248248+ .with_context(|| "Failed to create a new Zettel!")?;
249249+247250 let path = z.absolute_path(&kt.index).to_path_buf();
248251249252 drop(kt);
···258261 .selected()
259262 .expect("This must be the zettel we just edited");
260263264264+ // regenerate a fresh zettel list
265265+ self.zettel_list = ZettelList::new(
266266+ self.get_zettels_by_current_query().await?,
267267+ self.zettel_list.state,
268268+ self.zettel_list.width,
269269+ );
270270+261271 let Some(zid) = self.zettel_list.id_list.get(selected) else {
262272 return Ok(None);
263273 };
···271281 // reset the state of the component
272282 self.search.clear_query();
273283 self.zettel_list.state.select_first();
274274-275275- // regenerate a fresh zettel list
276276- self.zettel_list = ZettelList::new(
277277- self.get_zettels_by_current_query().await?,
278278- self.zettel_list.state,
279279- self.zettel_list.width,
280280- );
281284282285 self.zettel_view = ZettelView::from(&zettel);
283286 self.preview = Preview::from(zettel.content(&kt.index).clone());
+8-3
src/types/index.rs
···4949 let id: ZettelId = path.as_path().try_into()?;
5050 let (fm, body) = FrontMatter::extract_from_file(&path)?;
51515252- Ok((id, ZettelOnDisk { fm, body, path }))
5252+ Ok((
5353+ id,
5454+ ZettelOnDisk {
5555+ fm,
5656+ body,
5757+ path: path.canonicalize()?,
5858+ },
5959+ ))
5360 })
5461 .collect::<Result<Vec<_>>>()?
5562 .into_iter()
···165172 }
166173 Ok(())
167174 }
168168-169169- //TODO:need to process
170175171176 pub fn get_zod(&self, zid: &ZettelId) -> &ZettelOnDisk {
172177 self.zods.get(zid).expect("Invariant broken. Any zid we lookup must exist in the index, otherwise the db is corrupt or not sync'd.")
+16-4
src/types/kasten.rs
···1111};
1212use tracing::debug;
13131414-use crate::types::{Index, ZettelId};
1414+use crate::types::{FrontMatter, Index, ZettelId, index::ZettelOnDisk};
15151616#[derive(Debug, Clone)]
1717pub struct Kasten {
···9191 //NOTE: need to clone to get around borrowing rules but
9292 // ideally we dont have to do this, kind of cringe imo.
93939494- let path = path.as_ref();
9595- let zid = ZettelId::try_from(path)?;
9494+ let path = path.as_ref().canonicalize()?;
9595+ let zid = ZettelId::try_from(path.as_path())?;
9696+9797+ if !self.index.zods.contains_key(&zid) {
9898+ let (fm, body) = FrontMatter::extract_from_file(&path)?;
9999+ self.index.zods.insert(
100100+ zid.clone(),
101101+ ZettelOnDisk {
102102+ fm,
103103+ body,
104104+ path: path.clone(),
105105+ },
106106+ );
107107+ }
9610897109 // incase the path of the zettel changed
9898- self.index.update_path_for_zid(&zid, path.to_path_buf());
110110+ self.index.update_path_for_zid(&zid, path.clone());
99111 // let the index process the zettel, basically update the internal state of the zod
100112 self.index.process_zid(&zid)?;
101113 // and then we sync tags
+16-3
src/types/zettel/mod.rs
···44 DatabaseConnection, DateTime, TagEntity, ZettelActiveModel, ZettelEntity, ZettelModelEx,
55};
6677-use color_eyre::eyre::Result;
77+use color_eyre::eyre::{Context, Result};
88use dto::NanoId;
99use tokio::{fs::File, io::AsyncWriteExt};
1010···53535454 let local_file_path = format!("{nano_id}.md");
55555656+ let absolute_file_path = kt.root.clone().join(&local_file_path);
5757+5658 // now we have to create the file
5757- let mut file = File::create_new(kt.root.clone().join(&local_file_path)).await?;
5959+ let mut file = File::create_new(&absolute_file_path)
6060+ .await
6161+ .with_context(|| {
6262+ format!("Failed to create file at local file path: {local_file_path}")
6363+ })?;
58645965 let inserted = ZettelActiveModel::builder()
6066 .set_title(title.clone())
···79858086 file.write_all(front_matter.to_string().as_bytes()).await?;
81878282- kt.process_path(zettel.file_path.clone()).await?;
8888+ kt.process_path(&absolute_file_path)
8989+ .await
9090+ .with_context(|| {
9191+ format!(
9292+ "Kasten fails to process new Zettel at path: {}",
9393+ absolute_file_path.display(),
9494+ )
9595+ })?;
83968497 Ok(zettel.into())
8598 }