Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Correct missing database error #209

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed .DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.DS_Store

# Generated by Cargo
# will have compiled files and executables
/target/
Expand Down
15 changes: 3 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
FROM ekidd/rust-musl-builder:nightly AS builder

# Add the source code.
ADD . ./

# Fix permissions on source code.
RUN sudo chown -R rust:rust /home/rust
COPY --chown=rust:rust . ./

# Delete and re-install rustup in order to get the latest verison of Rust nightly.
# This is necessary due to a bug in Rust: https://github.com/rust-lang-nursery/rustup.rs/issues/1239
Expand All @@ -14,17 +11,11 @@ RUN curl https://sh.rustup.rs -sSf | \
sh -s -- -y && \
rustup target add x86_64-unknown-linux-musl

WORKDIR ~

# Build the `tdb-server` application.
RUN PKG_CONFIG_PATH=/usr/local/musl/lib/pkgconfig \
LDFLAGS=-L/usr/local/musl/lib \
cargo build --bin tdb-server --target x86_64-unknown-linux-musl --release
RUN cargo build --bin tdb-server --release

# Build the `tdb` application.
RUN PKG_CONFIG_PATH=/usr/local/musl/lib/pkgconfig \
LDFLAGS=-L/usr/local/musl/lib \
cargo build --bin tdb --target x86_64-unknown-linux-musl --release
RUN cargo build --bin tdb --release

# Now, we need to build the _real_ Docker container, copying in `tdb-server`
FROM alpine:latest
Expand Down
2 changes: 1 addition & 1 deletion bins/tdb/interactive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ pub fn run(cli: &mut TectonicClient) -> io::Result<()> {
_ => {
match cli.cmd(&line) {
Err(e) => {
println!("{}", e.description());
println!("{}", e);
}
Ok(msg) => {
println!("{}", msg);
Expand Down
4 changes: 2 additions & 2 deletions crates/tdb-cli/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ impl TectonicClient {
let res = std::str::from_utf8(&buf).unwrap().to_owned();
if success {
Ok(res)
} else if res.contains("ERR: DB") {
let book_name = res.split(" ").nth(2).unwrap();
} else if res.starts_with("ERR: No db named") {
let book_name = res.split(" ").nth(4).unwrap();
Err(TectonicError::DBNotFoundError(book_name.to_owned()))
} else {
Err(TectonicError::ServerError(res))
Expand Down
7 changes: 6 additions & 1 deletion crates/tdb-server-core/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ impl ReturnType {
{
ReturnType::Error(string.into())
}

pub fn missing_db(db_name: &BookName) -> ReturnType {
//NB On change update match in client as well
ReturnType::error(format!("No db named {}", db_name))
}
}


Expand Down Expand Up @@ -226,7 +231,7 @@ mod tests {
addr
));
assert_eq!(
ReturnType::Error("DB bnc_btc_eth not found.".into()),
ReturnType::Error("No db named bnc_btc_eth".into()),
resp
);
}
Expand Down
16 changes: 9 additions & 7 deletions crates/tdb-server-core/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,17 +272,19 @@ impl TectonicServer {
.unwrap_or_else(|| Arc::clone(&self.conn(addr).unwrap().book_entry));
match self.insert(up, &book_name).await {
Some(()) => ReturnType::string(""),
None => ReturnType::Error(Cow::Owned(format!("DB {} not found.", &book_name))),
None => ReturnType::missing_db(&book_name),
}
}
Insert(None, _) => ReturnType::error("Unable to parse line"),
Create(dbname) => match self.create(&dbname) {
Create(dbname) => {
match self.create(&dbname) {
Some(()) => ReturnType::string(format!("Created orderbook `{}`.", &dbname)),
None => ReturnType::error(format!("Unable to create orderbook `{}`.", &dbname)),
},
}
}
Subscribe(dbname) => {
self.sub(&dbname, addr);
ReturnType::string(format!("Subscribed to {}", dbname))
ReturnType::string(format!("Subscribed to {}", &dbname))
}
// Subscription => {
// let message = state.rx.as_ref().unwrap().try_recv();
Expand All @@ -303,20 +305,20 @@ impl TectonicServer {
Load(dbname) => {
match self.load_db(&dbname, addr) {
Some(_) => ReturnType::string(format!("Loaded orderbook `{}`.", &dbname)),
None => ReturnType::error(format!("No db named `{}`", dbname)),
None => ReturnType::missing_db(&dbname),
}
}
Use(dbname) => {
match self.use_db(&dbname, addr) {
Some(_) => ReturnType::string(format!("SWITCHED TO orderbook `{}`.", &dbname)),
None => ReturnType::error(format!("No db named `{}`", dbname)),
None => ReturnType::missing_db(&dbname),
}
}
Exists(dbname) => {
if self.exists(&dbname) {
ReturnType::ok()
} else {
ReturnType::error(format!("No db named `{}`", dbname))
ReturnType::missing_db(&dbname)
}
}
Get(cnt, fmt, rng, loc) =>
Expand Down