Skip to content

Commit 218aab2

Browse files
authored
From Failure into std::error::Error (#36)
* Update changelog * Move from failure to use stderr Related to datrs/hypercore#101
1 parent a8bfebe commit 218aab2

File tree

3 files changed

+40
-12
lines changed

3 files changed

+40
-12
lines changed

CHANGELOG.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
1+
## 2020-02-02, Version 1.0.0
2+
### Commits
3+
- [[`3de8d37a0c`](https://github.com/datrs/random-access-disk/commit/3de8d37a0c33bc15874de8870734bbdd07a8b24c)] 1.0.0 (substack)
4+
- [[`2fca3428a6`](https://github.com/datrs/random-access-disk/commit/2fca3428a6ca6e484c5b31c8b62422553641731e)] Merge pull request #28 from bltavares/bump-deps (Szabolcs Berecz)
5+
- [[`bebe8b4a2c`](https://github.com/datrs/random-access-disk/commit/bebe8b4a2c95dcd6d19c54ceb2fe854799af4ea4)] Update code to editio 2018 (Bruno Tavares)
6+
- [[`310dd8a5d7`](https://github.com/datrs/random-access-disk/commit/310dd8a5d79e2edcfbded8cb48a17c5949c6b276)] Bump random-access-storage to 3.0.0 (Bruno Tavares)
7+
- [[`95c3dad271`](https://github.com/datrs/random-access-disk/commit/95c3dad2715ade75c18337bb72f109573c9c08e3)] updated to use u64 (substack)
8+
- [[`1d884a4432`](https://github.com/datrs/random-access-disk/commit/1d884a443232528c2a0a9e03901cb12eca137ac1)] sync_all implementation (substack)
9+
- [[`bd9d0f6a86`](https://github.com/datrs/random-access-disk/commit/bd9d0f6a869d9f8225ae8582a5bfe5db6ca52578)] Update mkdirp requirement from 0.1.0 to 1.0.0 (dependabot-preview[bot])
10+
- [[`f9b34735e7`](https://github.com/datrs/random-access-disk/commit/f9b34735e79020ff2f39bef510026f5cf8bf02b3)] Update quickcheck requirement from 0.7.2 to 0.8.0 (dependabot[bot])
11+
- [[`4785a3dfa5`](https://github.com/datrs/random-access-disk/commit/4785a3dfa5aed164df833eafaeef4edda0dfd2c4)] Update changelog (Yoshua Wuyts)
12+
13+
### Stats
14+
```diff
15+
CHANGELOG.md | 16 ++++++-
16+
Cargo.toml | 25 ++++-----
17+
fuzz/Cargo.toml | 1 +-
18+
fuzz/fuzz_targets/fuzz_target_1.rs | 6 +--
19+
src/lib.rs | 109 ++++++++++++++++++++++++--------------
20+
tests/model.rs | 34 ++++--------
21+
tests/regression.rs | 5 +--
22+
tests/test.rs | 82 +++++++++++++++++++++++++++--
23+
8 files changed, 194 insertions(+), 84 deletions(-)
24+
```
25+
26+
127
## 2018-12-20, Version 0.8.0
228
### Commits
329
- [[`c7cdc2d39a`](https://github.com/datrs/random-access-disk/commit/c7cdc2d39a7d92103f7125c28d2451ecf6272578)] (cargo-release) version 0.8.0 (Yoshua Wuyts)

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ version = "1.0.0"
1010
edition = "2018"
1111

1212
[dependencies]
13-
failure = "0.1.6"
13+
anyhow = "1.0.26"
1414
mkdirp = "1.0.0"
1515
random-access-storage = "3.0.0"
1616

src/lib.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#![cfg_attr(feature = "nightly", doc(include = "../README.md"))]
44
#![cfg_attr(test, deny(warnings))]
55

6-
use failure::{ensure, Error};
6+
use anyhow::{anyhow, Error};
77
use random_access_storage::RandomAccess;
88
use std::fs::{self, OpenOptions};
99
use std::io::{Read, Seek, SeekFrom, Write};
@@ -31,7 +31,7 @@ impl RandomAccessDisk {
3131
}
3232

3333
impl RandomAccess for RandomAccessDisk {
34-
type Error = Error;
34+
type Error = Box<dyn std::error::Error + Sync + Send>;
3535

3636
fn write(&mut self, offset: u64, data: &[u8]) -> Result<(), Self::Error> {
3737
let mut file = self.file.as_ref().expect("self.file was None.");
@@ -59,15 +59,17 @@ impl RandomAccess for RandomAccessDisk {
5959
// reflect the state of the world.
6060
// #[cfg_attr(test, allow(unused_io_amount))]
6161
fn read(&mut self, offset: u64, length: u64) -> Result<Vec<u8>, Self::Error> {
62-
ensure!(
63-
(offset + length) as u64 <= self.length,
64-
format!(
65-
"Read bounds exceeded. {} < {}..{}",
66-
self.length,
67-
offset,
68-
offset + length
69-
)
70-
);
62+
if (offset + length) as u64 > self.length {
63+
return Err(
64+
anyhow!(
65+
"Read bounds exceeded. {} < {}..{}",
66+
self.length,
67+
offset,
68+
offset + length
69+
)
70+
.into(),
71+
);
72+
}
7173

7274
let mut file = self.file.as_ref().expect("self.file was None.");
7375
let mut buffer = vec![0; length as usize];

0 commit comments

Comments
 (0)