use miette::Diagnostic;
use thiserror::Error;
use crate::auth::AuthError;
use crate::config::ConfigError;
use crate::forge::ForgeError;
use crate::jj::JjError;
use crate::select::bookmark_gen::BookmarkGenError;
use crate::submit::SubmitError;
#[derive(Debug, Error, Diagnostic)]
pub enum StakkError {
#[error(transparent)]
#[diagnostic(transparent)]
Jj(#[from] JjError),
#[error(transparent)]
#[diagnostic(transparent)]
Forge(#[from] ForgeError),
#[error(transparent)]
#[diagnostic(transparent)]
Auth(#[from] AuthError),
#[error(transparent)]
#[diagnostic(transparent)]
Submit(#[from] SubmitError),
#[error(transparent)]
#[diagnostic(transparent)]
BookmarkGen(#[from] BookmarkGenError),
#[error(transparent)]
#[diagnostic(transparent)]
ExplicitSelection(#[from] crate::select::explicit::ExplicitSelectionError),
#[error(transparent)]
#[diagnostic(transparent)]
Config(#[from] ConfigError),
#[error("remote '{name}' is not a GitHub URL: {url}")]
#[diagnostic(
code(stakk::remote::not_github),
help(
"stakk expects an owner/repo remote URL, e.g. git@github.com:owner/repo.git; for a \
GitHub Enterprise Server host, also set --github-host"
)
)]
RemoteNotGithub { name: String, url: String },
#[error("remote '{name}' is on host '{host}', which is not a configured GitHub host: {url}")]
#[diagnostic(
code(stakk::remote::host_not_configured),
help(
"if {host} is a GitHub Enterprise Server host, name it with --github-host {host}, \
STAKK_GITHUB_HOST, github_host in stakk.toml, or GH_HOST"
)
)]
RemoteHostNotConfigured {
name: String,
url: String,
host: String,
},
#[error("remote '{name}' not found")]
#[diagnostic(
code(stakk::remote::not_found),
help("run `jj git remote list` to see available remotes")
)]
RemoteNotFound { name: String },
#[error("no GitHub remote found")]
#[diagnostic(
code(stakk::remote::no_github),
help(
"make sure this repository has a GitHub remote configured; for a GitHub Enterprise \
Server host, name it with --github-host, STAKK_GITHUB_HOST, github_host in \
stakk.toml, or GH_HOST"
)
)]
NoGithubRemote,
#[error("failed to load template '{path}': {reason}")]
#[diagnostic(
code(stakk::template::load_failed),
help("check that the file exists and is readable")
)]
TemplateLoadFailed { path: String, reason: String },
#[error("{0}")]
#[diagnostic(code(stakk::cli))]
Cli(#[from] clap::Error),
#[error("terminal I/O error: {0}")]
#[diagnostic(code(stakk::io))]
Io(#[from] std::io::Error),
#[error("interactive mode requires a terminal")]
#[diagnostic(
code(stakk::not_interactive),
help(
"select explicitly instead: stakk submit --keep <BOOKMARK> / --new <REV>[=<NAME>] — \
run `stakk docs agents` for the full non-interactive workflow"
)
)]
NotInteractive,
#[error("interrupted")]
#[diagnostic(code(stakk::interrupted))]
Interrupted,
}