mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
refactor: make error messages more user-friendly (#1935)
Co-authored-by: sxyazi <sxyazi@gmail.com>
This commit is contained in:
parent
0f9a3195b7
commit
87f7fb6b3b
11 changed files with 16 additions and 14 deletions
|
|
@ -91,7 +91,7 @@ impl Ueberzug {
|
||||||
.spawn();
|
.spawn();
|
||||||
|
|
||||||
if let Err(ref e) = result {
|
if let Err(ref e) = result {
|
||||||
warn!("ueberzugpp spawning failed: {e}");
|
warn!("Failed to start ueberzugpp: {e}");
|
||||||
}
|
}
|
||||||
Ok(result?)
|
Ok(result?)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,10 @@ function M:peek()
|
||||||
local files, bound, code = self.list_files({ "-p", tostring(self.file.url) }, self.skip, limit)
|
local files, bound, code = self.list_files({ "-p", tostring(self.file.url) }, self.skip, limit)
|
||||||
if code ~= 0 then
|
if code ~= 0 then
|
||||||
return ya.preview_widgets(self, {
|
return ya.preview_widgets(self, {
|
||||||
ui.Text(code == 2 and "File list in this archive is encrypted" or "Spawn `7z` and `7zz` both commands failed")
|
ui.Text(
|
||||||
:area(self.area),
|
code == 2 and "File list in this archive is encrypted"
|
||||||
|
or "Starting both `7z` and `7zz` failed. Do you have 7-zip installed?"
|
||||||
|
):area(self.area),
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -62,7 +64,7 @@ function M.spawn_7z(args)
|
||||||
end
|
end
|
||||||
|
|
||||||
if not child then
|
if not child then
|
||||||
return ya.err("spawn `7z` and `7zz` both commands failed, error code: " .. tostring(last_error))
|
return ya.err("Starting both `7z` and `7zz` failed, error code: " .. tostring(last_error))
|
||||||
end
|
end
|
||||||
return child, last_error
|
return child, last_error
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ function M:try_with(from, pwd, to)
|
||||||
local archive = require("archive")
|
local archive = require("archive")
|
||||||
local child, code = archive.spawn_7z { "x", "-aou", "-sccUTF-8", "-p" .. pwd, "-o" .. tostring(tmp), tostring(from) }
|
local child, code = archive.spawn_7z { "x", "-aou", "-sccUTF-8", "-p" .. pwd, "-o" .. tostring(tmp), tostring(from) }
|
||||||
if not child then
|
if not child then
|
||||||
fail("Spawn `7z` and `7zz` both commands failed, error code %s", code)
|
fail("Starting both `7z` and `7zz` failed, error code %s. Do you have 7-zip installed?", code)
|
||||||
end
|
end
|
||||||
|
|
||||||
local output, err = child:wait_with_output()
|
local output, err = child:wait_with_output()
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ function M:peek()
|
||||||
if output then
|
if output then
|
||||||
text = ui.Text.parse("----- File Type Classification -----\n\n" .. output.stdout)
|
text = ui.Text.parse("----- File Type Classification -----\n\n" .. output.stdout)
|
||||||
else
|
else
|
||||||
text = ui.Text(string.format("Spawn `%s` command returns %s", cmd, code))
|
text = ui.Text(string.format("Starting `%s` failed with error code %s. Do you have file(1) installed?", cmd, code))
|
||||||
end
|
end
|
||||||
|
|
||||||
ya.preview_widgets(self, { text:area(self.area):wrap(ui.Text.WRAP) })
|
ya.preview_widgets(self, { text:area(self.area):wrap(ui.Text.WRAP) })
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ function M:preload()
|
||||||
}):spawn()
|
}):spawn()
|
||||||
|
|
||||||
if not child then
|
if not child then
|
||||||
ya.err("spawn `magick` command returns " .. tostring(code))
|
ya.err(string.format("Starting `magick` failed with error code %s", code))
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ local function entry()
|
||||||
Command("fzf"):cwd(cwd):stdin(Command.INHERIT):stdout(Command.PIPED):stderr(Command.INHERIT):spawn()
|
Command("fzf"):cwd(cwd):stdin(Command.INHERIT):stdout(Command.PIPED):stderr(Command.INHERIT):spawn()
|
||||||
|
|
||||||
if not child then
|
if not child then
|
||||||
return fail("Spawn `fzf` failed with error code %s. Do you have it installed?", err)
|
return fail("Starting `fzf` failed with error code %s. Do you have it installed?", err)
|
||||||
end
|
end
|
||||||
|
|
||||||
local output, err = child:wait_with_output()
|
local output, err = child:wait_with_output()
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ function M:preload()
|
||||||
}):spawn()
|
}):spawn()
|
||||||
|
|
||||||
if not child then
|
if not child then
|
||||||
ya.err("spawn `magick` command returns " .. tostring(code))
|
ya.err(string.format("Starting `magick` failed with error code %s", code))
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ function M:fetch(job)
|
||||||
local cmd = os.getenv("YAZI_FILE_ONE") or "file"
|
local cmd = os.getenv("YAZI_FILE_ONE") or "file"
|
||||||
local child, code = Command(cmd):args({ "-bL", "--mime-type", "--" }):args(urls):stdout(Command.PIPED):spawn()
|
local child, code = Command(cmd):args({ "-bL", "--mime-type", "--" }):args(urls):stdout(Command.PIPED):spawn()
|
||||||
if not child then
|
if not child then
|
||||||
ya.err(string.format("Spawn `%s` command returns %s", cmd, code))
|
ya.err(string.format("Starting `%s` failed with error code %s", cmd, code))
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ function M:preload()
|
||||||
}):spawn()
|
}):spawn()
|
||||||
|
|
||||||
if not child then
|
if not child then
|
||||||
ya.err("Spawn `ffmpeg` process returns " .. tostring(code))
|
ya.err("Starting `ffmpeg` failed with error code " .. tostring(code))
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,7 @@ local function entry()
|
||||||
:spawn()
|
:spawn()
|
||||||
|
|
||||||
if not child then
|
if not child then
|
||||||
return fail("Spawn `zoxide` failed with error code %s. Do you have it installed?", err)
|
return fail("Starting `zoxide` failed with error code %s. Do you have it installed?", err)
|
||||||
end
|
end
|
||||||
|
|
||||||
local output, err = child:wait_with_output()
|
local output, err = child:wait_with_output()
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ impl Process {
|
||||||
let (id, cmd) = (task.id, task.cmd.clone());
|
let (id, cmd) = (task.id, task.cmd.clone());
|
||||||
let result = super::shell(task.into());
|
let result = super::shell(task.into());
|
||||||
if let Err(e) = result {
|
if let Err(e) = result {
|
||||||
AppProxy::notify_warn(&cmd.to_string_lossy(), format!("Failed to spawn process: {e}"));
|
AppProxy::notify_warn(&cmd.to_string_lossy(), format!("Failed to start process: {e}"));
|
||||||
return self.succ(id);
|
return self.succ(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -44,7 +44,7 @@ impl Process {
|
||||||
Ok(_) => self.succ(id)?,
|
Ok(_) => self.succ(id)?,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
self.prog.send(TaskProg::New(id, 0))?;
|
self.prog.send(TaskProg::New(id, 0))?;
|
||||||
self.fail(id, format!("Failed to spawn process: {e}"))?;
|
self.fail(id, format!("Failed to start process: {e}"))?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue