mirror of
https://github.com/johrpan/musicus.git
synced 2025-10-26 11:47:25 +01:00
database: Add error for missing items
This commit is contained in:
parent
d9746c8ab4
commit
ac14beb665
4 changed files with 21 additions and 46 deletions
|
|
@ -10,6 +10,9 @@ pub enum Error {
|
|||
#[error(transparent)]
|
||||
QueryError(#[from] diesel::result::Error),
|
||||
|
||||
#[error("Missing item dependency ({0} {1})")]
|
||||
MissingItem(&'static str, String),
|
||||
|
||||
#[error(transparent)]
|
||||
SendError(#[from] std::sync::mpsc::SendError<super::thread::Action>),
|
||||
|
||||
|
|
|
|||
|
|
@ -256,22 +256,18 @@ impl Database {
|
|||
|
||||
let recording = self
|
||||
.get_recording(&recording_id)?
|
||||
.ok_or(Error::Other(format!(
|
||||
"Failed to get recording ({}) for track ({}).",
|
||||
recording_id,
|
||||
row.id,
|
||||
)))?;
|
||||
.ok_or(Error::MissingItem("recording", recording_id))?;
|
||||
|
||||
let mut part_indices = Vec::new();
|
||||
|
||||
let work_parts = row
|
||||
.work_parts
|
||||
.split(',');
|
||||
let work_parts = row.work_parts.split(',');
|
||||
|
||||
for part_index in work_parts {
|
||||
if !part_index.is_empty() {
|
||||
let index = str::parse(part_index)
|
||||
.or(Err(Error::Other(format!("Failed to parse part index from '{}'.", row.work_parts))))?;
|
||||
let index = str::parse(part_index).or(Err(Error::Other(format!(
|
||||
"Failed to parse part index from '{}'.",
|
||||
row.work_parts
|
||||
))))?;
|
||||
|
||||
part_indices.push(index);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -218,47 +218,31 @@ impl Database {
|
|||
person: match row.person {
|
||||
Some(id) => Some(
|
||||
self.get_person(&id)?
|
||||
.ok_or(Error::Other(format!(
|
||||
"Failed to get person ({}) for recording ({}).",
|
||||
id,
|
||||
row.id,
|
||||
)))?
|
||||
.ok_or(Error::MissingItem("person", id))?,
|
||||
),
|
||||
None => None,
|
||||
},
|
||||
ensemble: match row.ensemble {
|
||||
Some(id) => Some(
|
||||
self.get_ensemble(&id)?
|
||||
.ok_or(Error::Other(format!(
|
||||
"Failed to get ensemble ({}) for recording ({}).",
|
||||
id,
|
||||
row.id,
|
||||
)))?
|
||||
.ok_or(Error::MissingItem("ensemble", id))?,
|
||||
),
|
||||
None => None,
|
||||
},
|
||||
role: match row.role {
|
||||
Some(id) => Some(
|
||||
self.get_instrument(&id)?
|
||||
.ok_or(Error::Other(format!(
|
||||
"Failed to get instrument ({}) for recording ({}).",
|
||||
id,
|
||||
row.id,
|
||||
)))?
|
||||
.ok_or(Error::MissingItem("instrument", id))?,
|
||||
),
|
||||
None => None,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
let work_id = &row.work;
|
||||
let work_id = row.work;
|
||||
let work = self
|
||||
.get_work(work_id)?
|
||||
.ok_or(Error::Other(format!(
|
||||
"Failed to get work ({}) for recording ({}).",
|
||||
work_id,
|
||||
row.id,
|
||||
)))?;
|
||||
.get_work(&work_id)?
|
||||
.ok_or(Error::MissingItem("work", work_id))?;
|
||||
|
||||
let recording_description = Recording {
|
||||
id: row.id,
|
||||
|
|
|
|||
|
|
@ -206,14 +206,10 @@ impl Database {
|
|||
.load::<InstrumentationRow>(&self.connection)?;
|
||||
|
||||
for instrumentation in instrumentations {
|
||||
let id = &instrumentation.instrument;
|
||||
let id = instrumentation.instrument;
|
||||
instruments.push(
|
||||
self.get_instrument(id)?
|
||||
.ok_or(Error::Other(format!(
|
||||
"Failed to get instrument ({}) for work ({}).",
|
||||
id,
|
||||
row.id,
|
||||
)))?
|
||||
self.get_instrument(&id)?
|
||||
.ok_or(Error::MissingItem("instrument", id))?,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -242,14 +238,10 @@ impl Database {
|
|||
});
|
||||
}
|
||||
|
||||
let person_id = &row.composer;
|
||||
let person_id = row.composer;
|
||||
let person = self
|
||||
.get_person(person_id)?
|
||||
.ok_or(Error::Other(format!(
|
||||
"Failed to get person ({}) for work ({}).",
|
||||
person_id,
|
||||
row.id,
|
||||
)))?;
|
||||
.get_person(&person_id)?
|
||||
.ok_or(Error::MissingItem("person", person_id))?;
|
||||
|
||||
Ok(Work {
|
||||
id: row.id,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue