forked from M-Labs/artiq
1
0
Fork 0

config: error instead of empty value if key not found

This commit is contained in:
mwojcik 2022-05-19 15:25:01 +08:00 committed by Sébastien Bourdeauducq
parent 8599be5550
commit 4bdb4c8e11
2 changed files with 7 additions and 2 deletions

View File

@ -9,6 +9,7 @@ pub enum Error {
MissingSeparator { offset: usize },
Utf8Error(str::Utf8Error),
NoFlash,
KeyNotFound
}
impl fmt::Display for Error {
@ -28,6 +29,8 @@ impl fmt::Display for Error {
write!(f, "{}", err),
&Error::NoFlash =>
write!(f, "flash memory is not present"),
&Error::KeyNotFound =>
write!(f, "key not found")
}
}
}
@ -156,14 +159,16 @@ mod imp {
f(Lock::take().and_then(|lock| {
let mut iter = Iter::new(lock.data());
let mut value = &[][..];
let mut found = false;
while let Some(result) = iter.next() {
let (record_key, record_value) = result?;
if key.as_bytes() == record_key {
found = true;
// last write wins
value = record_value
}
}
Ok(value)
if found { Ok(value) } else { Err(Error::KeyNotFound) }
}))
}

View File

@ -529,7 +529,7 @@ fn flash_kernel_worker(io: &Io, aux_mutex: &Mutex,
config::read(config_key, |result| {
match result {
Ok(kernel) if kernel.len() > 0 => unsafe {
Ok(kernel) => unsafe {
// kernel CPU cannot access the SPI flash address space directly,
// so make a copy.
kern_load(io, &mut session, Vec::from(kernel).as_ref())