refactor: centralize constants, eliminate unwraps, remove dead code, resolve TODOs
- R13+R16: Replace .expect() with .context()? in main.rs and identity.rs - R17+R18+R19: Fix unwrap() calls in helpers and js-engine - R20+R21: Remove #[allow(dead_code)] annotations and delete truly dead code - R22-R26: Create constants.rs module, replace 21 hardcoded values across 12 files - R28+R29: LND/DWN timeouts already present — verified - R30-R33: Remove TODO comments, implement marketplace payment check Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -164,12 +164,16 @@ impl AtomicFile {
|
||||
impl std::ops::Deref for AtomicFile {
|
||||
type Target = File;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
self.file.as_ref().unwrap()
|
||||
self.file
|
||||
.as_ref()
|
||||
.expect("AtomicFile already consumed by save() or rollback()")
|
||||
}
|
||||
}
|
||||
impl std::ops::DerefMut for AtomicFile {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
self.file.as_mut().unwrap()
|
||||
self.file
|
||||
.as_mut()
|
||||
.expect("AtomicFile already consumed by save() or rollback()")
|
||||
}
|
||||
}
|
||||
impl Drop for AtomicFile {
|
||||
@@ -177,7 +181,11 @@ impl Drop for AtomicFile {
|
||||
if let Some(file) = self.file.take() {
|
||||
drop(file);
|
||||
let path = std::mem::take(&mut self.tmp_path);
|
||||
tokio::spawn(async move { tokio::fs::remove_file(path).await.unwrap() });
|
||||
tokio::spawn(async move {
|
||||
if let Err(e) = tokio::fs::remove_file(&path).await {
|
||||
tracing::warn!("failed to remove tmp file {}: {}", path.display(), e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -230,7 +238,13 @@ impl<T: 'static + Send> TimedResource<T> {
|
||||
|
||||
pub async fn get(self) -> Option<T> {
|
||||
let _ = self.ready.send(());
|
||||
self.handle.await.unwrap()
|
||||
match self.handle.await {
|
||||
Ok(val) => val,
|
||||
Err(e) => {
|
||||
tracing::error!("TimedResource task panicked: {}", e);
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_timed_out(&self) -> bool {
|
||||
@@ -250,7 +264,7 @@ pub async fn spawn_local<
|
||||
tokio::runtime::Builder::new_current_thread()
|
||||
.enable_all()
|
||||
.build()
|
||||
.unwrap()
|
||||
.expect("failed to build tokio current-thread runtime for spawn_local")
|
||||
.block_on(async move {
|
||||
let set = LocalSet::new();
|
||||
send.send(set.spawn_local(fut()).into())
|
||||
@@ -258,5 +272,6 @@ pub async fn spawn_local<
|
||||
set.await
|
||||
})
|
||||
});
|
||||
recv.await.unwrap()
|
||||
recv.await
|
||||
.expect("spawn_local thread terminated before sending task handle")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user