Skip to content

Commit 3386be9

Browse files
committed
fix: Correct missing database error
1 parent c8fc836 commit 3386be9

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

bins/tdb/interactive.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ pub fn run(cli: &mut TectonicClient) -> io::Result<()> {
118118
_ => {
119119
match cli.cmd(&line) {
120120
Err(e) => {
121-
println!("{}", e.description());
121+
println!("{}", e);
122122
}
123123
Ok(msg) => {
124124
println!("{}", msg);

crates/tdb-cli/src/client.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ impl TectonicClient {
7474
let res = std::str::from_utf8(&buf).unwrap().to_owned();
7575
if success {
7676
Ok(res)
77-
} else if res.contains("ERR: DB") {
78-
let book_name = res.split(" ").nth(2).unwrap();
77+
} else if res.starts_with("ERR: No db named") {
78+
let book_name = res.split(" ").nth(4).unwrap();
7979
Err(TectonicError::DBNotFoundError(book_name.to_owned()))
8080
} else {
8181
Err(TectonicError::ServerError(res))

crates/tdb-server-core/src/handler.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ impl ReturnType {
2929
{
3030
ReturnType::Error(string.into())
3131
}
32+
33+
pub fn missing_db(db_name: &BookName) -> ReturnType {
34+
//NB On change update match in client as well
35+
ReturnType::error(format!("No db named {}", db_name))
36+
}
3237
}
3338

3439

@@ -226,7 +231,7 @@ mod tests {
226231
addr
227232
));
228233
assert_eq!(
229-
ReturnType::Error("DB bnc_btc_eth not found.".into()),
234+
ReturnType::Error("No db named bnc_btc_eth".into()),
230235
resp
231236
);
232237
}

crates/tdb-server-core/src/state.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -272,17 +272,19 @@ impl TectonicServer {
272272
.unwrap_or_else(|| Arc::clone(&self.conn(addr).unwrap().book_entry));
273273
match self.insert(up, &book_name).await {
274274
Some(()) => ReturnType::string(""),
275-
None => ReturnType::Error(Cow::Owned(format!("DB {} not found.", &book_name))),
275+
None => ReturnType::missing_db(&book_name),
276276
}
277277
}
278278
Insert(None, _) => ReturnType::error("Unable to parse line"),
279-
Create(dbname) => match self.create(&dbname) {
279+
Create(dbname) => {
280+
match self.create(&dbname) {
280281
Some(()) => ReturnType::string(format!("Created orderbook `{}`.", &dbname)),
281282
None => ReturnType::error(format!("Unable to create orderbook `{}`.", &dbname)),
282-
},
283+
}
284+
}
283285
Subscribe(dbname) => {
284286
self.sub(&dbname, addr);
285-
ReturnType::string(format!("Subscribed to {}", dbname))
287+
ReturnType::string(format!("Subscribed to {}", &dbname))
286288
}
287289
// Subscription => {
288290
// let message = state.rx.as_ref().unwrap().try_recv();
@@ -303,20 +305,20 @@ impl TectonicServer {
303305
Load(dbname) => {
304306
match self.load_db(&dbname, addr) {
305307
Some(_) => ReturnType::string(format!("Loaded orderbook `{}`.", &dbname)),
306-
None => ReturnType::error(format!("No db named `{}`", dbname)),
308+
None => ReturnType::missing_db(&dbname),
307309
}
308310
}
309311
Use(dbname) => {
310312
match self.use_db(&dbname, addr) {
311313
Some(_) => ReturnType::string(format!("SWITCHED TO orderbook `{}`.", &dbname)),
312-
None => ReturnType::error(format!("No db named `{}`", dbname)),
314+
None => ReturnType::missing_db(&dbname),
313315
}
314316
}
315317
Exists(dbname) => {
316318
if self.exists(&dbname) {
317319
ReturnType::ok()
318320
} else {
319-
ReturnType::error(format!("No db named `{}`", dbname))
321+
ReturnType::missing_db(&dbname)
320322
}
321323
}
322324
Get(cnt, fmt, rng, loc) =>

0 commit comments

Comments
 (0)