Skip to content

Commit 2ffb008

Browse files
authored
Merge pull request #97 from Synicix/crypto
Add additional error handling for crypto.rs and accompany tests
2 parents 9f26b3d + 13436cb commit 2ffb008

File tree

9 files changed

+15
-13
lines changed

9 files changed

+15
-13
lines changed

src/core/crypto.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,9 @@ pub fn hash_buffer(buffer: impl AsRef<[u8]>) -> String {
5050
///
5151
/// Will return error if unable to access file.
5252
pub fn hash_file(filepath: impl AsRef<Path>) -> Result<String> {
53-
hash_stream(
54-
&mut File::open(&filepath).context(selector::InvalidFilepath {
55-
path: filepath.as_ref(),
56-
})?,
57-
)
53+
hash_stream(&mut File::open(&filepath).context(selector::InvalidPath {
54+
path: filepath.as_ref(),
55+
})?)
5856
}
5957
/// Evaluate checksum hash of a directory.
6058
///
@@ -64,7 +62,10 @@ pub fn hash_file(filepath: impl AsRef<Path>) -> Result<String> {
6462
pub fn hash_dir(dirpath: impl AsRef<Path>) -> Result<String> {
6563
let summary: BTreeMap<String, String> = dirpath
6664
.as_ref()
67-
.read_dir()?
65+
.read_dir()
66+
.context(selector::InvalidPath {
67+
path: dirpath.as_ref(),
68+
})?
6869
.map(|path| {
6970
let access_path = path?.path();
7071
Ok((

src/core/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ impl fmt::Debug for OrcaError {
122122
match &self.kind {
123123
Kind::AgentCommunicationFailure { backtrace, .. }
124124
| Kind::IncompletePacket { backtrace, .. }
125-
| Kind::InvalidFilepath { backtrace, .. }
125+
| Kind::InvalidPath { backtrace, .. }
126126
| Kind::MissingInfo { backtrace, .. }
127127
| Kind::BollardError { backtrace, .. }
128128
| Kind::ChronoParseError { backtrace, .. }

src/core/operator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl Operator for JoinOperator {
4040
.filter_map(|(parent_stream, parent_packets)| {
4141
(parent_stream != &stream_name).then_some(parent_packets.clone())
4242
})
43-
.chain(vec![vec![packet.clone()]].into_iter())
43+
.chain(vec![vec![packet.clone()]])
4444
.collect::<Vec<_>>();
4545
drop(received_packets);
4646

src/core/store/filestore.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ impl LocalFileStore {
194194
Ok((
195195
serde_yaml::from_str(
196196
&fs::read_to_string(path.clone())
197-
.context(selector::InvalidFilepath { path })?,
197+
.context(selector::InvalidPath { path })?,
198198
)?,
199199
None,
200200
hash.to_owned(),

src/uniffi/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub(crate) enum Kind {
3737
backtrace: Option<Backtrace>,
3838
},
3939
#[snafu(display("{source} ({path:?})."))]
40-
InvalidFilepath {
40+
InvalidPath {
4141
path: PathBuf,
4242
source: io::Error,
4343
backtrace: Option<Backtrace>,

src/uniffi/orchestrator/docker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl Orchestrator for LocalDockerOrchestrator {
9494
let location = namespace_lookup[&image_info.namespace].join(&image_info.path);
9595
let byte_stream = FramedRead::new(
9696
File::open(&location)
97-
.context(selector::InvalidFilepath { path: &location })
97+
.context(selector::InvalidPath { path: &location })
9898
.await?,
9999
BytesCodec::new(),
100100
)

tests/crypto.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![expect(missing_docs, clippy::panic_in_result_fn, reason = "OK in tests.")]
2+
pub mod fixture;
23

34
use orcapod::{
45
core::crypto::{hash_buffer, hash_dir, hash_file},
5 Bytes
Loading

tests/model.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ fn pod_job_to_yaml() -> Result<()> {
104104
fn hash_pod_result() -> Result<()> {
105105
assert_eq!(
106106
pod_result_style(&NAMESPACE_LOOKUP_READ_ONLY)?.hash,
107-
"35abb8180349bed1f3ea8c0d84e98000ec3ace904624e94e678783891a7e710e",
107+
"e752d86d4fc5435bfa4564ba951851530f5cf2228586c2f488c2ca9e7bcc7ed1",
108108
"Hash didn't match."
109109
);
110110
Ok(())
@@ -129,7 +129,7 @@ fn pod_result_to_yaml() -> Result<()> {
129129
location:
130130
namespace: default
131131
path: output/result2.jpeg
132-
checksum: da71a1b5f8ca6ebd1edfd11df4c83078fc50d0e6a4c9b3d642ba397d81d8e883
132+
checksum: a1458fc7d7d9d23a66feae88b5a89f1756055bdbb6be02fdf672f7d31ed92735
133133
assigned_name: simple-endeavour
134134
status: Completed
135135
created: 1737922307

0 commit comments

Comments
 (0)