1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#![allow(missing_docs)]
use crate::metadata::{Id, PropertyType, TypeId, TypeKind};
#[derive(Debug, thiserror::Error)]
pub enum InitError {
#[error("database error")]
Db(#[from] sqlx::Error),
#[error("only SQLite or MySQL are supported by ml-metadata")]
UnsupportedDatabase,
#[error("schema version {actual} is not supported (supported version is {expected})")]
UnsupportedSchemaVersion {
actual: i32,
expected: i32,
},
}
#[derive(Debug, thiserror::Error)]
pub enum GetError {
#[error("database error")]
Db(#[from] sqlx::Error),
}
#[derive(Debug, thiserror::Error)]
pub enum PutError {
#[error("database error")]
Db(#[from] sqlx::Error),
#[error("{item_id} has a type {type_id} that doesn't exist")]
TypeNotFound { type_id: TypeId, item_id: Id },
#[error("{type_kind} type with the name {type_name} already exists")]
TypeAlreadyExists {
type_kind: TypeKind,
type_name: String,
},
#[error("{item_id} has an undefined property {property_name:?}({property_type})")]
UndefinedProperty {
item_id: Id,
property_name: String,
property_type: PropertyType,
},
#[error("{item_id} has a name {item_name:?} that already exists")]
NameAlreadyExists { item_id: Id, item_name: String },
#[error("{item_id} is not found")]
NotFound { item_id: Id },
}
impl From<GetError> for PutError {
fn from(e: GetError) -> Self {
let GetError::Db(e) = e;
Self::Db(e)
}
}
#[derive(Debug, thiserror::Error)]
pub enum PostError {
#[error("database error")]
Db(#[from] sqlx::Error),
#[error("{type_kind} type {type_id} is not found")]
TypeNotFound {
type_kind: TypeKind,
type_id: TypeId,
},
#[error("new {type_kind} with the type {type_id} has an undefined property {property_name:?}")]
UndefinedProperty {
type_kind: TypeKind,
type_id: TypeId,
property_name: String,
},
#[error("new {type_kind} has a name {item_name:?} that already exists")]
NameAlreadyExists {
type_kind: TypeKind,
item_name: String,
},
}
impl From<GetError> for PostError {
fn from(e: GetError) -> Self {
let GetError::Db(e) = e;
Self::Db(e)
}
}