Skip to content

Commit

Permalink
feat(cli): detailed start failure error feedback
Browse files Browse the repository at this point in the history
This commit ensures that after 3 failures to start komorebi with
'komorebic start', 'komorebi.exe' will be run directly in order to show
the detailed error output to the end user.
  • Loading branch information
LGUG2Z committed Apr 20, 2024
1 parent 793e81d commit aff1081
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions komorebi-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub use komorebi::NotificationEvent;
pub use komorebi::RuleDebug;
pub use komorebi::StackbarConfig;
pub use komorebi::State;
pub use komorebi::StaticConfig;
pub use komorebi::TabsConfig;
pub use komorebi_core::ActiveWindowBorderStyle;
pub use komorebi_core::Arrangement;
Expand Down
1 change: 1 addition & 0 deletions komorebic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ edition = "2021"
[dependencies]
derive-ahk = { path = "../derive-ahk" }
komorebi-core = { path = "../komorebi-core" }
komorebi-client = { path = "../komorebi-client" }

clap = { version = "4", features = ["derive", "wrap_help"] }
color-eyre = { workspace = true }
Expand Down
28 changes: 26 additions & 2 deletions komorebic/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1391,6 +1391,11 @@ fn main() -> Result<()> {
}
}

// Check that this file adheres to the schema static config schema as the last step,
// so that more basic errors above can be shown to the error before schema-specific
// errors
let _ = serde_json::from_str::<komorebi_client::StaticConfig>(&config_source)?;

if config_whkd.exists() {
println!("Found {}; key bindings will be loaded from here when whkd is started, and you can start it automatically using the --whkd flag\n", config_whkd.to_string_lossy());
} else {
Expand Down Expand Up @@ -1775,7 +1780,7 @@ fn main() -> Result<()> {
};

let mut flags = vec![];
if let Some(config) = arg.config {
if let Some(config) = &arg.config {
let path = resolve_home_path(config)?;
if !path.is_file() {
bail!("could not find file: {}", path.display());
Expand Down Expand Up @@ -1810,9 +1815,10 @@ fn main() -> Result<()> {
)
};

let mut attempts = 0;
let mut running = false;

while !running {
while !running && attempts <= 2 {
match powershell_script::run(&script) {
Ok(_) => {
println!("{script}");
Expand All @@ -1833,7 +1839,25 @@ fn main() -> Result<()> {
running = true;
} else {
println!("komorebi.exe did not start... Trying again");
attempts += 1;
}
}

if !running {
println!("\nRunning komorebi.exe directly for detailed error output\n");
if let Some(config) = arg.config {
let path = resolve_home_path(config)?;
if let Ok(output) = Command::new("komorebi.exe")
.arg(format!("'--config=\"{}\"'", path.display()))
.output()
{
println!("{}", String::from_utf8(output.stderr)?);
}
} else if let Ok(output) = Command::new("komorebi.exe").output() {
println!("{}", String::from_utf8(output.stderr)?);
}

return Ok(());
}

if arg.whkd {
Expand Down

0 comments on commit aff1081

Please sign in to comment.