fix: InvalidArgs error message should include the command name (#3433)

This commit is contained in:
Kan-Ru Chen
2022-02-13 23:25:50 +09:00
committed by GitHub
parent 679fe1fedd
commit 28e4845a89
2 changed files with 4 additions and 3 deletions

View File

@@ -50,8 +50,9 @@ pub trait CommandArg<'de, R: Runtime>: Sized {
/// Automatically implement [`CommandArg`] for any type that can be deserialized.
impl<'de, D: Deserialize<'de>, R: Runtime> CommandArg<'de, R> for D {
fn from_command(command: CommandItem<'de, R>) -> Result<Self, InvokeError> {
let name = command.name;
let arg = command.key;
Self::deserialize(command).map_err(|e| crate::Error::InvalidArgs(arg, e).into())
Self::deserialize(command).map_err(|e| crate::Error::InvalidArgs(name, arg, e).into())
}
}

View File

@@ -58,8 +58,8 @@ pub enum Error {
#[error("'{0}' not on the allowlist (https://tauri.studio/docs/api/config#tauri.allowlist)")]
ApiNotAllowlisted(String),
/// Invalid args when running a command.
#[error("invalid args for command `{0}`: {1}")]
InvalidArgs(&'static str, serde_json::Error),
#[error("invalid args `{1}` for command `{0}`: {2}")]
InvalidArgs(&'static str, &'static str, serde_json::Error),
/// Encountered an error in the setup hook,
#[error("error encountered during setup hook: {0}")]
Setup(Box<dyn std::error::Error + Send>),