mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-21 23:01: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();
|
||||
|
||||
if let Err(ref e) = result {
|
||||
warn!("ueberzugpp spawning failed: {e}");
|
||||
warn!("Failed to start ueberzugpp: {e}");
|
||||
}
|
||||
Ok(result?)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,8 +7,10 @@ function M:peek()
|
|||
local files, bound, code = self.list_files({ "-p", tostring(self.file.url) }, self.skip, limit)
|
||||
if code ~= 0 then
|
||||
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")
|
||||
:area(self.area),
|
||||
ui.Text(
|
||||
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
|
||||
|
||||
|
|
@ -62,7 +64,7 @@ function M.spawn_7z(args)
|
|||
end
|
||||
|
||||
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
|
||||
return child, last_error
|
||||
end
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ function M:try_with(from, pwd, to)
|
|||
local archive = require("archive")
|
||||
local child, code = archive.spawn_7z { "x", "-aou", "-sccUTF-8", "-p" .. pwd, "-o" .. tostring(tmp), tostring(from) }
|
||||
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
|
||||
|
||||
local output, err = child:wait_with_output()
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ function M:peek()
|
|||
if output then
|
||||
text = ui.Text.parse("----- File Type Classification -----\n\n" .. output.stdout)
|
||||
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
|
||||
|
||||
ya.preview_widgets(self, { text:area(self.area):wrap(ui.Text.WRAP) })
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ function M:preload()
|
|||
}):spawn()
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ local function entry()
|
|||
Command("fzf"):cwd(cwd):stdin(Command.INHERIT):stdout(Command.PIPED):stderr(Command.INHERIT):spawn()
|
||||
|
||||
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
|
||||
|
||||
local output, err = child:wait_with_output()
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ function M:preload()
|
|||
}):spawn()
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ function M:fetch(job)
|
|||
local cmd = os.getenv("YAZI_FILE_ONE") or "file"
|
||||
local child, code = Command(cmd):args({ "-bL", "--mime-type", "--" }):args(urls):stdout(Command.PIPED):spawn()
|
||||
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
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ function M:preload()
|
|||
}):spawn()
|
||||
|
||||
if not child then
|
||||
ya.err("Spawn `ffmpeg` process returns " .. tostring(code))
|
||||
ya.err("Starting `ffmpeg` failed with error code " .. tostring(code))
|
||||
return 0
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ local function entry()
|
|||
:spawn()
|
||||
|
||||
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
|
||||
|
||||
local output, err = child:wait_with_output()
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ impl Process {
|
|||
let (id, cmd) = (task.id, task.cmd.clone());
|
||||
let result = super::shell(task.into());
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
@ -44,7 +44,7 @@ impl Process {
|
|||
Ok(_) => self.succ(id)?,
|
||||
Err(e) => {
|
||||
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