Skip to content

Commit

Permalink
graceful missing instance for attr
Browse files Browse the repository at this point in the history
  • Loading branch information
TBS1996 committed Jan 4, 2025
1 parent 110ba2a commit 3d2cf42
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
14 changes: 4 additions & 10 deletions speki-core/src/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,14 @@ pub struct Attribute {

impl Attribute {
/// Fills the pattern with the instance
pub async fn name(&self, instance: CardId) -> String {
let card_text = self
.card_provider
.load(instance)
.await
.unwrap()
.print()
.await;
pub async fn name(&self, instance: CardId) -> Option<String> {
let card_text = self.card_provider.load(instance).await?.print().await;

if self.pattern.contains("{}") {
Some(if self.pattern.contains("{}") {
self.pattern.replace("{}", &card_text)
} else {
format!("{}: {}", &self.pattern, card_text)
}
})
}

pub fn from_dto(dto: AttributeDTO, card_provider: CardProvider) -> Self {
Expand Down
1 change: 1 addition & 0 deletions speki-core/src/card/card_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ impl CardTrait for AttributeCard {
.unwrap()
.name(self.instance)
.await
.unwrap_or_else(|| "oops, instance is deleted".to_string())
}
}

Expand Down

0 comments on commit 3d2cf42

Please sign in to comment.