Skip to content

Commit ceaf768

Browse files
committed
Print a nicer error when failing to create xdg directories
When the config or cache directories fail to get created for whichever reason, we currently exit gitui with a pretty undescriptive error. This at least prints the relevant path so that the user can attempt to fix them. Fixes #2652.
1 parent f5893d9 commit ceaf768

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3131
### Fixes
3232
* resolve `core.hooksPath` relative to `GIT_WORK_TREE` [[@naseschwarz](https://github.com/naseschwarz)] ([#2571](https://github.com/gitui-org/gitui/issues/2571))
3333
* yanking commit ranges no longer generates incorrect dotted range notations, but lists each individual commit [[@naseschwarz](https://github.com/naseschwarz)] (https://github.com/gitui-org/gitui/issues/2576)
34+
* print slightly nicer errors when failing to create a directory [[@linkmauve](https://github.com/linkmauve)] (https://github.com/gitui-org/gitui/pull/2728)
3435

3536
## [0.27.0] - 2024-01-14
3637

src/args.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ pub fn process_cmdline() -> Result<CliArgs> {
4949
.map_or_else(|| PathBuf::from("theme.ron"), PathBuf::from);
5050

5151
let confpath = get_app_config_path()?;
52-
fs::create_dir_all(&confpath)?;
52+
if let Err(err) = fs::create_dir_all(&confpath) {
53+
eprintln!("Impossible to create the config directory {confpath:?}:");
54+
return Err(err.into());
55+
}
5356
let theme = confpath.join(arg_theme);
5457

5558
let notify_watcher: bool =
@@ -154,7 +157,10 @@ fn get_app_cache_path() -> Result<PathBuf> {
154157
.ok_or_else(|| anyhow!("failed to find os cache dir."))?;
155158

156159
path.push("gitui");
157-
fs::create_dir_all(&path)?;
160+
if let Err(err) = fs::create_dir_all(&path) {
161+
eprintln!("Impossible to create the cache directory {path:?}:");
162+
return Err(err.into());
163+
}
158164
Ok(path)
159165
}
160166

0 commit comments

Comments
 (0)