Skip to content

Commit b9fbda6

Browse files
authored
Fix panic in case of Exception received from server due to bad authentication (#86)
Refs: suharev7/clickhouse-rs#226 Fixes: #84
2 parents f904924 + 649bcd1 commit b9fbda6

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/interpreter/context.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,11 @@ pub struct Context {
3838
}
3939

4040
impl Context {
41-
pub async fn new(options: ChDigOptions, cb_sink: cursive::CbSink) -> Result<ContextArc> {
42-
let clickhouse = Arc::new(ClickHouse::new(options.clickhouse.clone()).await?);
41+
pub async fn new(
42+
options: ChDigOptions,
43+
clickhouse: Arc<ClickHouse>,
44+
cb_sink: cursive::CbSink,
45+
) -> Result<ContextArc> {
4346
let server_version = clickhouse.version();
4447
let worker = Worker::new();
4548
let background_runner_cv = Arc::new((Mutex::new(()), Condvar::new()));

src/main.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ use anyhow::Result;
22
use backtrace::Backtrace;
33
use flexi_logger::{LogSpecification, Logger};
44
use std::panic::{self, PanicHookInfo};
5+
use std::sync::Arc;
56

67
mod common;
78
mod interpreter;
89
mod view;
910

1011
use crate::{
11-
interpreter::{options, Context, ContextArc},
12+
interpreter::{options, ClickHouse, Context, ContextArc},
1213
view::Navigation,
1314
};
1415

@@ -37,6 +38,10 @@ fn panic_hook(info: &PanicHookInfo<'_>) {
3738
async fn main() -> Result<()> {
3839
let options = options::parse();
3940

41+
// Initialize it before any backends (otherwise backend will prepare terminal for TUI app, and
42+
// panic hook will clear the screen).
43+
let clickhouse = Arc::new(ClickHouse::new(options.clickhouse.clone()).await?);
44+
4045
panic::set_hook(Box::new(|info| {
4146
panic_hook(info);
4247
}));
@@ -63,7 +68,7 @@ async fn main() -> Result<()> {
6368
.start()?;
6469

6570
// FIXME: should be initialized before cursive, otherwise on error it clears the terminal.
66-
let context: ContextArc = Context::new(options, siv.cb_sink().clone()).await?;
71+
let context: ContextArc = Context::new(options, clickhouse, siv.cb_sink().clone()).await?;
6772

6873
siv.chdig(context.clone());
6974

0 commit comments

Comments
 (0)