janhq/jan · error · ServerError::InvalidArgument

Invalid argument: {0}

Error message

Invalid argument: {0}

What it means

The ServerError::InvalidArgument(String) variant in the tauri-plugin-llamacpp plugin. Its Display is "Invalid argument: {0}". On serialization it maps to LlamacppError code INVALID_ARGUMENT with message "Invalid configuration argument provided." and the reason string in details. Unlike the other variants it is constructed explicitly (not via #[from]) when a command validates its inputs and rejects a bad config value.

Source

Thrown at src-tauri/plugins/tauri-plugin-llamacpp/src/error.rs:203

    let candidate = candidate.trim_matches(['\'', '"', '(', ')', ',', '.'].as_ref());
    if looks_like_library(candidate) && !found.iter().any(|f| f == candidate) {
        found.push(candidate.to_string());
    }
}

// Error type for server commands
#[derive(Debug, thiserror::Error)]
pub enum ServerError {
    #[error(transparent)]
    Llamacpp(#[from] LlamacppError),

    #[error("IO error: {0}")]
    Io(#[from] std::io::Error),

    #[error("Tauri error: {0}")]
    Tauri(#[from] tauri::Error),

    #[error("Invalid argument: {0}")]
    InvalidArgument(String),
}

// impl serialization for tauri
impl serde::Serialize for ServerError {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: serde::Serializer,
    {
        let error_to_serialize: LlamacppError = match self {
            ServerError::Llamacpp(err) => err.clone(),
            ServerError::Io(e) => LlamacppError::new(
                ErrorCode::IoError,
                "An input/output error occurred.".into(),
                Some(e.to_string()),
            ),
            ServerError::Tauri(e) => LlamacppError::new(
                ErrorCode::InternalError,

View on GitHub (pinned to fad3f12a14)

Solutions

  1. Validate and clamp config values on the frontend before invoking the command.
  2. Read the serialized `details` to see exactly which argument was rejected.
  3. Reset the offending setting to its default and retry.
  4. Update the plugin if a previously valid value is now rejected due to tightened validation.

Example fix

// Rust
pub fn start_server(cfg: Config) -> ServerResult<()> {
    if cfg.n_gpu_layers < 0 {
        return Err(ServerError::InvalidArgument("n_gpu_layers must be >= 0".into()))
    }
    Ok(())
}

// Frontend
try { await invoke('start_server', { cfg }) }
catch (e) {
  const err = JSON.parse(e.message)
  if (err.code === 'INVALID_ARGUMENT') alert(err.details)
}
Defensive patterns

Strategy: validation

Validate before calling

function validateConfig(cfg: any) {
  if (typeof cfg.n_gpu_layers !== 'number' || cfg.n_gpu_layers < 0)
    throw new Error('n_gpu_layers must be a non-negative number')
  if (typeof cfg.ctx_size !== 'number' || cfg.ctx_size <= 0)
    throw new Error('ctx_size must be a positive number')
}
validateConfig(cfg)
await invoke('start_server', { cfg })

Try / catch

try {
  await invoke('start_server', { cfg })
} catch (e) {
  const err = JSON.parse((e as any).message ?? '{}')
  if (err.code === 'INVALID_ARGUMENT') showFieldError(err.details)
  else throw e
}

Prevention

When it happens

Trigger: A server command receives a config value that fails validation (out-of-range number, malformed string, unknown enum) and returns Err(ServerError::InvalidArgument(msg)).

Common situations: Context size set to 0 or negative; n_gpu_layers negative; an unknown backend name; a port number out of range; required field missing from the config payload.

Related errors


AI-assisted analysis of janhq/jan@fad3f12a14 (2026-08-12). Data as JSON: /api/errors/cae57aed2ae272c0. Report an issue: GitHub.