tauri-apps/tauri · error

failed to convert base64 to string

Error message

failed to convert base64 to string

What it means

decode_base64 converts its OsStr input to &str and panics if the base64 credential blob is not valid UTF-8. This is used for decoding Apple notarization credentials (e.g. key content) supplied as base64, so the library assumes callers pass well-formed base64 text.

Solutions

  1. Re-export the base64 credential ensuring it is plain ASCII text
  2. Re-encode the source key (e.g. base64 the .p8 file again) and store it as UTF-8 text
  3. Read credentials from files using String::from_utf8 validation before use

Example fix

// before
let raw = std::fs::read("key.b64").unwrap();
notarize(path, &creds_from_raw_bytes(raw), true).unwrap();
// after
let raw = std::fs::read("key.b64").unwrap();
let text = String::from_utf8(raw).expect("credential must be UTF-8 base64");
notarize(path, &creds_from_text(text), true).unwrap();
Defensive patterns

Strategy: validation

Validate before calling

let bytes = std::fs::read("key.b64")?;
let text = String::from_utf8(bytes).expect("base64 credential must be UTF-8");
assert!(!text.trim().is_empty());

Type guard

fn is_utf8_osstr(s: &OsStr) -> bool { s.to_str().is_some() }

Prevention

When it happens

Trigger: Passing an AppleNotarizationCredentials field (such as key or issuer content) as an OsStr containing non-UTF-8 bytes into the credential-decoding path.

Common situations: Reading a base64 credential from a file opened in binary mode with corrupted bytes, or copying a key with terminal/encoding munging on Windows or unusual locales.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of tauri-apps/tauri@460ec35447 (2026-09-18). Data as JSON: /api/errors/1d644979966489d2. Report an issue: GitHub.

Appendix: source

Thrown at crates/tauri-macos-sign/src/lib.rs:339

          self
            .arg("--key-id")
            .arg(key_id)
            .arg("--key")
            .arg(key_path)
            .arg("--issuer")
            .arg(issuer),
        )
      }
    }
  }
}

fn decode_base64(base64_input: &OsStr, out_path: &Path) -> Result<()> {
  use base64::Engine;

  let input = base64_input
    .to_str()
    .expect("failed to convert base64 to string");

  // strip whitespace before decoding
  let cleaned: String = input.chars().filter(|c| !c.is_ascii_whitespace()).collect();

  let decoded = base64::engine::general_purpose::STANDARD
    .decode(&cleaned)
    .map_err(Error::Base64Decode)?;

  std::fs::write(out_path, &decoded).map_err(|error| Error::Fs {
    context: "failed to write decoded certificate",
    path: out_path.to_path_buf(),
    error,
  })?;

  Ok(())
}

fn assert_command(

View on GitHub (pinned to 460ec35447)