Skip to content

Commit dc40545

Browse files
committed
io::Error::other purge
- don't send a special error if sending to an expected pipe fails irpc will already produce an io error BrokenPipe, which is more informative than just "error" - don't use other("...") for unsupported ops
1 parent e1456f9 commit dc40545

File tree

4 files changed

+27
-47
lines changed

4 files changed

+27
-47
lines changed

src/store/fs.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,9 +1378,7 @@ async fn copy_with_progress<T: CopyProgress>(
13781378
let buf: &mut [u8] = &mut buf[..remaining];
13791379
file.read_exact_at(offset, buf)?;
13801380
target.write_all(buf)?;
1381-
tx.try_send(T::from_offset(offset))
1382-
.await
1383-
.map_err(|_e| io::Error::other(""))?;
1381+
tx.try_send(T::from_offset(offset)).await?;
13841382
yield_now().await;
13851383
offset += buf.len() as u64;
13861384
}

src/store/fs/import.rs

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,8 @@ async fn import_bytes_tiny_impl(
196196
let size = cmd.data.len() as u64;
197197
// send the required progress events
198198
// AddProgressItem::Done will be sent when finishing the import!
199-
tx.send(AddProgressItem::Size(size))
200-
.await
201-
.map_err(|_e| io::Error::other("error"))?;
202-
tx.send(AddProgressItem::CopyDone)
203-
.await
204-
.map_err(|_e| io::Error::other("error"))?;
199+
tx.send(AddProgressItem::Size(size)).await?;
200+
tx.send(AddProgressItem::CopyDone).await?;
205201
Ok(if raw_outboard_size(size) == 0 {
206202
// the thing is so small that it does not even need an outboard
207203
ImportEntry {
@@ -286,12 +282,8 @@ async fn import_byte_stream_impl(
286282
) -> io::Result<ImportEntry> {
287283
let ImportByteStreamRequest { format, scope } = cmd;
288284
let import_source = get_import_source(stream, tx, &options).await?;
289-
tx.send(AddProgressItem::Size(import_source.size()))
290-
.await
291-
.map_err(|_e| io::Error::other("error"))?;
292-
tx.send(AddProgressItem::CopyDone)
293-
.await
294-
.map_err(|_e| io::Error::other("error"))?;
285+
tx.send(AddProgressItem::Size(import_source.size())).await?;
286+
tx.send(AddProgressItem::CopyDone).await?;
295287
compute_outboard(import_source, format, scope, options, tx).await
296288
}
297289

@@ -344,18 +336,14 @@ async fn get_import_source(
344336
data.extend_from_slice(&chunk);
345337
}
346338
// todo: don't send progress for every chunk if the chunks are small?
347-
tx.try_send(AddProgressItem::CopyProgress(size))
348-
.await
349-
.map_err(|_e| io::Error::other("error"))?;
339+
tx.try_send(AddProgressItem::CopyProgress(size)).await?;
350340
}
351341
Ok(if let Some((mut file, temp_path)) = disk {
352342
while let Some(chunk) = stream.next().await {
353343
let chunk = chunk?;
354344
file.write_all(&chunk)?;
355345
size += chunk.len() as u64;
356-
tx.send(AddProgressItem::CopyProgress(size))
357-
.await
358-
.map_err(|_e| io::Error::other("error"))?;
346+
tx.send(AddProgressItem::CopyProgress(size)).await?;
359347
}
360348
ImportSource::TempFile(temp_path, file, size)
361349
} else {
@@ -473,14 +461,10 @@ async fn import_path_impl(
473461
}
474462

475463
let size = path.metadata()?.len();
476-
tx.send(AddProgressItem::Size(size))
477-
.await
478-
.map_err(|_e| io::Error::other("error"))?;
464+
tx.send(AddProgressItem::Size(size)).await?;
479465
let import_source = if size <= options.inline.max_data_inlined {
480466
let data = std::fs::read(path)?;
481-
tx.send(AddProgressItem::CopyDone)
482-
.await
483-
.map_err(|_e| io::Error::other("error"))?;
467+
tx.send(AddProgressItem::CopyDone).await?;
484468
ImportSource::Memory(data.into())
485469
} else if mode == ImportMode::TryReference {
486470
// reference where it is. We are going to need the file handle to
@@ -500,9 +484,7 @@ async fn import_path_impl(
500484
);
501485
// copy from path to temp_path
502486
let file = OpenOptions::new().read(true).open(&temp_path)?;
503-
tx.send(AddProgressItem::CopyDone)
504-
.await
505-
.map_err(|_| io::Error::other("error"))?;
487+
tx.send(AddProgressItem::CopyDone).await?;
506488
ImportSource::TempFile(temp_path, file, size)
507489
};
508490
compute_outboard(import_source, format, batch, options, tx).await

src/store/mem.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -837,8 +837,7 @@ async fn export_path_impl(
837837
entry.0.state.borrow().data().read_exact_at(offset, buf)?;
838838
file.write_all(buf)?;
839839
tx.try_send(ExportProgressItem::CopyProgress(offset))
840-
.await
841-
.map_err(|_e| io::Error::other(""))?;
840+
.await?;
842841
yield_now().await;
843842
}
844843
Ok(())

src/store/readonly_mem.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,9 @@ impl Actor {
9696
async fn handle_command(&mut self, cmd: Command) -> Option<irpc::channel::oneshot::Sender<()>> {
9797
match cmd {
9898
Command::ImportBao(ImportBaoMsg { tx, .. }) => {
99-
tx.send(Err(api::Error::from(io::Error::other(
100-
"import not supported",
101-
))))
102-
.await
103-
.ok();
99+
tx.send(Err(unsupported("import not supported").into()))
100+
.await
101+
.ok();
104102
}
105103
Command::WaitIdle(WaitIdleMsg { tx, .. }) => {
106104
if self.tasks.is_empty() {
@@ -112,17 +110,17 @@ impl Actor {
112110
}
113111
}
114112
Command::ImportBytes(ImportBytesMsg { tx, .. }) => {
115-
tx.send(io::Error::other("import not supported").into())
113+
tx.send(unsupported("import not supported").into())
116114
.await
117115
.ok();
118116
}
119117
Command::ImportByteStream(ImportByteStreamMsg { tx, .. }) => {
120-
tx.send(io::Error::other("import not supported").into())
118+
tx.send(unsupported("import not supported").into())
121119
.await
122120
.ok();
123121
}
124122
Command::ImportPath(ImportPathMsg { tx, .. }) => {
125-
tx.send(io::Error::other("import not supported").into())
123+
tx.send(unsupported("import not supported").into())
126124
.await
127125
.ok();
128126
}
@@ -163,7 +161,7 @@ impl Actor {
163161
}
164162
Command::CreateTag(cmd) => {
165163
cmd.tx
166-
.send(Err(io::Error::other("create tag not supported").into()))
164+
.send(Err(unsupported("create tag not supported").into()))
167165
.await
168166
.ok();
169167
}
@@ -172,19 +170,19 @@ impl Actor {
172170
}
173171
Command::RenameTag(cmd) => {
174172
cmd.tx
175-
.send(Err(io::Error::other("rename tag not supported").into()))
173+
.send(Err(unsupported("rename tag not supported").into()))
176174
.await
177175
.ok();
178176
}
179177
Command::DeleteTags(cmd) => {
180178
cmd.tx
181-
.send(Err(io::Error::other("delete tags not supported").into()))
179+
.send(Err(unsupported("delete tags not supported").into()))
182180
.await
183181
.ok();
184182
}
185183
Command::DeleteBlobs(cmd) => {
186184
cmd.tx
187-
.send(Err(io::Error::other("delete blobs not supported").into()))
185+
.send(Err(unsupported("delete blobs not supported").into()))
188186
.await
189187
.ok();
190188
}
@@ -213,7 +211,7 @@ impl Actor {
213211
}
214212
Command::SetTag(cmd) => {
215213
cmd.tx
216-
.send(Err(io::Error::other("set tag not supported").into()))
214+
.send(Err(unsupported("set tag not supported").into()))
217215
.await
218216
.ok();
219217
}
@@ -264,6 +262,10 @@ impl Actor {
264262
}
265263
}
266264

265+
fn unsupported(text: &str) -> io::Error {
266+
io::Error::new(io::ErrorKind::Unsupported, text)
267+
}
268+
267269
async fn export_bao(
268270
hash: Hash,
269271
entry: Option<CompleteStorage>,
@@ -413,8 +415,7 @@ async fn export_path_impl(
413415
data.as_ref().read_exact_at(offset, buf)?;
414416
file.write_all(buf)?;
415417
tx.try_send(ExportProgressItem::CopyProgress(offset))
416-
.await
417-
.map_err(|_e| io::Error::other("error"))?;
418+
.await?;
418419
yield_now().await;
419420
}
420421
Ok(())

0 commit comments

Comments
 (0)