From aa709556f9be5771c1f0ab373c36a5508061b7c7 Mon Sep 17 00:00:00 2001 From: "Daniel X. Pape" Date: Fri, 10 Jan 2025 17:44:32 -0800 Subject: [PATCH] Added warning about calling register_tags() when decoding --- src/ur_decodable.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/ur_decodable.rs b/src/ur_decodable.rs index b8cc688..d8496e9 100644 --- a/src/ur_decodable.rs +++ b/src/ur_decodable.rs @@ -7,8 +7,13 @@ use dcbor::CBORTaggedDecodable; /// A type that can be decoded from a UR. pub trait URDecodable: CBORTaggedDecodable { fn from_ur(ur: impl AsRef) -> Result where Self: Sized { - ur.as_ref().check_type(Self::cbor_tags()[0].name().as_ref().unwrap().clone())?; - Self::from_untagged_cbor(ur.as_ref().clone().into()) + let tag = &Self::cbor_tags()[0]; + if let Some(name) = tag.name().as_ref() { + ur.as_ref().check_type(name.clone())?; + Self::from_untagged_cbor(ur.as_ref().clone().into()) + } else { + panic!("CBOR tag {} must have a name. Did you call `register_tags()`?", tag.value()); + } } fn from_ur_string(ur_string: impl Into) -> Result where Self: Sized {