toeverything/AFFiNE · error · std::io::Error

InvalidData

InvalidData

Error message

path bytes are not valid UTF-8

What it means

Raised in `resolve_path` when a TypedPath cannot be represented as valid UTF-8: `path.to_str()` returns None after the Windows-encoding check. OneNote import filesystem operations need a UTF-8 str to build a PathBuf, so paths with invalid or non-UTF-8 encodings are rejected; the faulting input is the supplied TypedPath.

Source

Thrown at packages/frontend/native/src/import/onenote/windows_fs.rs:77

  fn open_file(&self, path: TypedPath) -> Result<Arc<dyn FileSource>, Error> {
    let file = File::open(resolve_path(path)?)?;
    let byte_length = file.metadata()?.len();
    Ok(Arc::new(CachedFileSource::new(WindowsFileSource { file, byte_length })))
  }
}

fn resolve_path(path: TypedPath) -> Result<PathBuf, Error> {
  let path = if path.is_windows() {
    path.to_path_buf()
  } else {
    path
      .with_windows_encoding_checked()
      .map_err(|error| Error::new(std::io::ErrorKind::InvalidInput, error))?
  };
  let path = path
    .to_str()
    .ok_or_else(|| Error::new(std::io::ErrorKind::InvalidData, "path bytes are not valid UTF-8"))?;
  to_verbatim(PathBuf::from(path))
}

fn as_typed_path(path: &Path) -> Result<TypedPathBuf, Error> {
  let path = path
    .to_str()
    .ok_or_else(|| Error::new(std::io::ErrorKind::InvalidData, "path is not valid UTF-8"))?;
  Ok(TypedPath::windows(path.as_bytes()).to_path_buf())
}

fn to_verbatim(path: PathBuf) -> Result<PathBuf, Error> {
  let path = std::path::absolute(path)?.to_string_lossy().replace('/', "\\");
  if path.starts_with(r"\\?\") {
    return Ok(PathBuf::from(path));
  }
  let mut verbatim = OsString::new();
  if let Some(path) = path.strip_prefix(r"\\") {
    verbatim.push(r"\\?\UNC\");

View on GitHub (pinned to b4c8548c09)

Solutions

  1. Use paths that are valid UTF-8.
  2. Convert the path encoding before import.
Defensive patterns

Strategy: validation

When it happens

Trigger: Raised in resolve_path when a Windows file path obtained for OneNote import cannot be converted to a UTF-8 str.

Common situations: The OneNote section path contains non-UTF-8 bytes (e.g. legacy encodings). Rename the file or folder to valid UTF-8 characters.


AI-assisted analysis of toeverything/AFFiNE@b4c8548c09 (2026-08-18). Data as JSON: /api/errors/61dfc42c1c804d28. Report an issue: GitHub.