Show errors when failing to create directories on startup (#10326)
Release Notes: - Improved error reporting on startup ([#9036](https://github.com/zed-industries/zed/issues/9036)).
This commit is contained in:
parent
0533923f91
commit
759c65d4bd
1 changed files with 39 additions and 10 deletions
|
@ -21,7 +21,9 @@ use editor::{Editor, EditorMode};
|
||||||
use env_logger::Builder;
|
use env_logger::Builder;
|
||||||
use fs::RealFs;
|
use fs::RealFs;
|
||||||
use futures::{future, StreamExt};
|
use futures::{future, StreamExt};
|
||||||
use gpui::{App, AppContext, AsyncAppContext, Context, SemanticVersion, Task, ViewContext};
|
use gpui::{
|
||||||
|
App, AppContext, AsyncAppContext, Context, SemanticVersion, Task, ViewContext, VisualContext,
|
||||||
|
};
|
||||||
use image_viewer;
|
use image_viewer;
|
||||||
use isahc::{prelude::Configurable, Request};
|
use isahc::{prelude::Configurable, Request};
|
||||||
use language::LanguageRegistry;
|
use language::LanguageRegistry;
|
||||||
|
@ -70,11 +72,31 @@ use zed::{
|
||||||
#[global_allocator]
|
#[global_allocator]
|
||||||
static GLOBAL: MiMalloc = MiMalloc;
|
static GLOBAL: MiMalloc = MiMalloc;
|
||||||
|
|
||||||
|
fn fail_to_launch(e: anyhow::Error) {
|
||||||
|
App::new().run(move |cx| {
|
||||||
|
let window = cx.open_window(gpui::WindowOptions::default(), |cx| cx.new_view(|_| gpui::Empty));
|
||||||
|
window.update(cx, |_, cx| {
|
||||||
|
let response = cx.prompt(gpui::PromptLevel::Critical, "Zed failed to launch", Some(&format!("{}\n\nFor help resolving this, please open an issue on https://github.com/zed-industries/zed", e)), &["Exit"]);
|
||||||
|
|
||||||
|
cx.spawn(|_, mut cx| async move {
|
||||||
|
response.await?;
|
||||||
|
cx.update(|cx| {
|
||||||
|
cx.quit()
|
||||||
|
})
|
||||||
|
}).detach_and_log_err(cx);
|
||||||
|
}).log_err();
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
menu::init();
|
menu::init();
|
||||||
zed_actions::init();
|
zed_actions::init();
|
||||||
|
|
||||||
init_paths();
|
if let Err(e) = init_paths() {
|
||||||
|
fail_to_launch(e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
init_logger();
|
init_logger();
|
||||||
|
|
||||||
if ensure_only_instance() != IsOnlyInstance::Yes {
|
if ensure_only_instance() != IsOnlyInstance::Yes {
|
||||||
|
@ -509,14 +531,21 @@ async fn restore_or_create_workspace(app_state: Arc<AppState>, cx: AsyncAppConte
|
||||||
.log_err();
|
.log_err();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn init_paths() {
|
fn init_paths() -> anyhow::Result<()> {
|
||||||
std::fs::create_dir_all(&*util::paths::CONFIG_DIR).expect("could not create config path");
|
for path in [
|
||||||
std::fs::create_dir_all(&*util::paths::EXTENSIONS_DIR)
|
&*util::paths::CONFIG_DIR,
|
||||||
.expect("could not create extensions path");
|
&*util::paths::EXTENSIONS_DIR,
|
||||||
std::fs::create_dir_all(&*util::paths::LANGUAGES_DIR).expect("could not create languages path");
|
&*util::paths::LANGUAGES_DIR,
|
||||||
std::fs::create_dir_all(&*util::paths::DB_DIR).expect("could not create database path");
|
&*util::paths::DB_DIR,
|
||||||
std::fs::create_dir_all(&*util::paths::LOGS_DIR).expect("could not create logs path");
|
&*util::paths::LOGS_DIR,
|
||||||
std::fs::create_dir_all(&*util::paths::TEMP_DIR).expect("could not create tmp path");
|
&*util::paths::TEMP_DIR,
|
||||||
|
]
|
||||||
|
.iter()
|
||||||
|
{
|
||||||
|
std::fs::create_dir_all(path)
|
||||||
|
.map_err(|e| anyhow!("Could not create directory {:?}: {}", path, e))?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn init_logger() {
|
fn init_logger() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue