Skip to content

Fix panic in case of Exception received from server due to bad authentication #86

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

Merged
merged 2 commits into from
Apr 15, 2025
Merged
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
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions src/interpreter/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ pub struct Context {
}

impl Context {
pub async fn new(options: ChDigOptions, cb_sink: cursive::CbSink) -> Result<ContextArc> {
let clickhouse = Arc::new(ClickHouse::new(options.clickhouse.clone()).await?);
pub async fn new(
options: ChDigOptions,
clickhouse: Arc<ClickHouse>,
cb_sink: cursive::CbSink,
) -> Result<ContextArc> {
let server_version = clickhouse.version();
let worker = Worker::new();
let background_runner_cv = Arc::new((Mutex::new(()), Condvar::new()));
Expand Down
9 changes: 7 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ use anyhow::Result;
use backtrace::Backtrace;
use flexi_logger::{LogSpecification, Logger};
use std::panic::{self, PanicHookInfo};
use std::sync::Arc;

mod common;
mod interpreter;
mod view;

use crate::{
interpreter::{options, Context, ContextArc},
interpreter::{options, ClickHouse, Context, ContextArc},
view::Navigation,
};

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

// Initialize it before any backends (otherwise backend will prepare terminal for TUI app, and
// panic hook will clear the screen).
let clickhouse = Arc::new(ClickHouse::new(options.clickhouse.clone()).await?);

panic::set_hook(Box::new(|info| {
panic_hook(info);
}));
Expand All @@ -63,7 +68,7 @@ async fn main() -> Result<()> {
.start()?;

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

siv.chdig(context.clone());

Expand Down
Loading