dmtrKovalenko/fff · error

File path is null or invalid UTF-8

Error message

File path is null or invalid UTF-8

What it means

fff_track_query validates the file_path argument with cstr_to_str; a NULL pointer or non-UTF-8 bytes yield this error. The library needs a real path string to canonicalize and record in the query history database.

Solutions

  1. Ensure file_path is a valid, NUL-terminated UTF-8 C string.
  2. Skip the tracking call when no file is selected instead of passing NULL.
  3. Convert non-UTF-8 paths lossily or reject them in the host before calling.
  4. Confirm the string buffer outlives the call.

Example fix

// before
fff_track_query(inst, query, NULL); // error
// after
if (file_path != NULL) { fff_track_query(inst, query, file_path); }
Defensive patterns

Strategy: validation

Validate before calling

if file_path == nil or #file_path == 0 then return end

Type guard

local function is_trackable_path(p) return type(p) == 'string' and #p > 0 and vim.fn.filereadable(p) == 1 end

Try / catch

local ok, res = pcall(fff.track_query, inst, q, file_path)
if not ok or res.is_err then log('tracking skipped') end

Prevention

When it happens

Trigger: Calling fff_track_query with file_path = NULL, an unterminated buffer, or a path containing bytes that are not valid UTF-8 (common with non-UTF-8 filesystem encodings).

Common situations: Host editor passes a buffer name that is not valid UTF-8; caller passes an empty/unset path because no file is open; manual C string construction missing the NUL terminator.

Understand the failure class

Related errors


AI-assisted analysis of dmtrKovalenko/fff@7f8537e70f (2026-09-10). Data as JSON: /api/errors/bf55926686a59413. Report an issue: GitHub.

Appendix: source

Thrown at crates/fff-c/src/lib.rs:1079

#[unsafe(no_mangle)]
pub unsafe extern "C" fn fff_track_query(
    fff_handle: *mut c_void,
    query: *const c_char,
    file_path: *const c_char,
) -> *mut FffResult {
    let inst = match unsafe { instance_ref(fff_handle) } {
        Ok(i) => i,
        Err(e) => return e,
    };

    let query_str = match unsafe { cstr_to_str(query) } {
        Some(s) => s,
        None => return FffResult::err("Query is null or invalid UTF-8"),
    };

    let path_str = match unsafe { cstr_to_str(file_path) } {
        Some(s) => s,
        None => return FffResult::err("File path is null or invalid UTF-8"),
    };

    let file_path = match fff::path_utils::canonicalize(path_str) {
        Ok(p) => p,
        Err(e) => return FffResult::err(&format!("Failed to canonicalize path: {}", e)),
    };

    let project_path = {
        let guard = match inst.picker.read() {
            Ok(g) => g,
            Err(_) => return FffResult::ok_int(0),
        };
        match guard.as_ref() {
            Some(p) => p.base_path().to_path_buf(),
            None => return FffResult::ok_int(0),
        }
    };

View on GitHub (pinned to 7f8537e70f)