ballista-cli 55.0.0

Command Line Client for Ballista distributed query engine.
Documentation
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License.  You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.

#[cfg(not(feature = "web"))]
use crate::tui::event::Event;
use config::ConfigError;
#[cfg(not(feature = "web"))]
use tokio::sync::mpsc::error::SendError;
use tracing_subscriber::filter::ParseError;

#[derive(Debug)]
pub enum TuiError {
    Reqwest(reqwest::Error),
    Json(serde_json::Error),
    IO(std::io::Error),
    #[cfg(not(feature = "web"))]
    SendError(Box<SendError<Event>>),
    Config(Box<ConfigError>),
    Tracing(Box<ParseError>),
}

impl std::fmt::Display for TuiError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            TuiError::Reqwest(err) => write!(f, "Reqwest error: {err}"),
            TuiError::Json(err) => write!(f, "JSON error: {err}"),
            TuiError::IO(err) => write!(f, "An IO error occurred: {err}"),
            #[cfg(not(feature = "web"))]
            TuiError::SendError(err) => write!(f, "Send error: {err}"),
            TuiError::Config(err) => write!(f, "Config error: {err}"),
            TuiError::Tracing(err) => write!(f, "Tracing error: {err}"),
        }
    }
}

impl std::error::Error for TuiError {
    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
        match self {
            TuiError::Reqwest(err) => Some(err),
            TuiError::Json(err) => Some(err),
            TuiError::IO(err) => Some(err),
            #[cfg(not(feature = "web"))]
            TuiError::SendError(err) => Some(err.as_ref()),
            TuiError::Config(err) => Some(err.as_ref()),
            TuiError::Tracing(err) => Some(err.as_ref()),
        }
    }
}

impl From<reqwest::Error> for TuiError {
    fn from(err: reqwest::Error) -> Self {
        TuiError::Reqwest(err)
    }
}

impl From<serde_json::Error> for TuiError {
    fn from(err: serde_json::Error) -> Self {
        TuiError::Json(err)
    }
}

#[cfg(not(feature = "web"))]
impl From<SendError<Event>> for TuiError {
    fn from(err: SendError<Event>) -> Self {
        TuiError::SendError(Box::new(err))
    }
}

impl From<std::io::Error> for TuiError {
    fn from(err: std::io::Error) -> Self {
        TuiError::IO(err)
    }
}

impl From<ConfigError> for TuiError {
    fn from(err: ConfigError) -> Self {
        TuiError::Config(Box::new(err))
    }
}

impl From<ParseError> for TuiError {
    fn from(err: ParseError) -> Self {
        TuiError::Tracing(Box::new(err))
    }
}