world_id_proof/artifacts/
error.rs1#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
3pub enum ZkArtifactKind {
4 QueryMaterial,
5 NullifierMaterial,
6 OwnershipProver,
7 OwnershipVerifier,
8}
9
10impl std::fmt::Display for ZkArtifactKind {
11 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
12 let name = match self {
13 Self::QueryMaterial => "query proof material",
14 Self::NullifierMaterial => "nullifier proof material",
15 Self::OwnershipProver => "ownership prover",
16 Self::OwnershipVerifier => "ownership verifier",
17 };
18 f.write_str(name)
19 }
20}
21
22#[derive(Debug, thiserror::Error)]
24pub enum ZkArtifactError {
25 #[error(
28 "{kind} is not provided by this ZK artifact source{}",
29 fmt_detail(detail)
30 )]
31 NotProvided {
32 kind: ZkArtifactKind,
33 detail: Option<String>,
35 },
36 #[error("{kind} is unavailable: {reason}")]
38 Unavailable {
39 kind: ZkArtifactKind,
40 reason: &'static str,
41 },
42 #[error("failed to load {kind}: {message}")]
44 Load {
45 kind: ZkArtifactKind,
46 message: String,
47 },
48}
49
50impl ZkArtifactError {
51 #[must_use]
53 pub fn kind(&self) -> ZkArtifactKind {
54 match self {
55 Self::NotProvided { kind, .. }
56 | Self::Unavailable { kind, .. }
57 | Self::Load { kind, .. } => *kind,
58 }
59 }
60
61 pub fn load(kind: ZkArtifactKind, error: impl Into<eyre::Report>) -> Self {
63 Self::Load {
64 kind,
65 message: format!("{:#}", error.into()),
66 }
67 }
68}
69
70fn fmt_detail(detail: &Option<String>) -> String {
71 detail
72 .as_deref()
73 .map(|d| format!(" ({d})"))
74 .unwrap_or_default()
75}