dmtrKovalenko/fff · error

Failed to init tracing

Error message

Failed to init tracing: {}

What it means

When opts.log_file_path is provided, the library initializes its tracing/logging subsystem via fff::log::init_tracing. If that initialization fails (the underlying error is embedded in the message), instance creation aborts rather than continuing without logging.

Solutions

  1. Create the parent directory of log_file_path and ensure it is writable.
  2. Use a valid log_level value ('trace','debug','info','warn','error') or pass NULL.
  3. Point log_file_path at a writable location (e.g. tmp dir) to isolate the issue.
  4. Omit log_file_path (NULL) to skip logging setup entirely if logging is optional.

Example fix

// before
opts.log_file_path = "/var/log/fff.log"; // read-only for the user
// after
mkdirp("/home/me/.cache/fff");
opts.log_file_path = "/home/me/.cache/fff/fff.log";
opts.log_level = "debug";
Defensive patterns

Strategy: try-catch

Validate before calling

const fs = require('fs');
if (logPath) fs.mkdirSync(path.dirname(logPath), { recursive: true });
if (logLevel && !['trace','debug','info','warn','error'].includes(logLevel.toLowerCase())) throw new Error(`invalid log_level: ${logLevel}`);

Try / catch

try {
  createInstance({ ...opts, log_file_path: logPath });
} catch (e) {
  if (/Failed to init tracing/.test(e.message)) {
    createInstance({ ...opts, log_file_path: null }); // proceed without logging
  } else throw e;
}

Prevention

When it happens

Trigger: Passing a log_file_path whose directory does not exist or is not writable; an invalid log_level string; the log file being locked/unwritable on disk.

Common situations: Pointing logs at a read-only directory or a path outside the sandbox; typos in log_level (must be a valid tracing level like 'debug'); container users mapping a read-only volume for the log path.

Understand the failure class

Background: "open() failed", "failed to open file", "cannot create file" — what a file open error means and how to fix it — this error's family across 42 libraries.

Related errors


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

Appendix: source

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

        return FffResult::err("opts is null");
    }
    let opts = unsafe { &*opts };
    if opts.version == 0 || opts.version > FFF_CREATE_OPTIONS_VERSION {
        return FffResult::err(&format!(
            "Unsupported FffCreateOptions version {} (library understands up to {})",
            opts.version, FFF_CREATE_OPTIONS_VERSION
        ));
    }

    let base_path_str = match unsafe { cstr_to_str(opts.base_path) } {
        Some(s) if !s.is_empty() => s.to_string(),
        _ => return FffResult::err("opts.base_path is null or empty"),
    };

    if let Some(log_path) = unsafe { optional_cstr(opts.log_file_path) } {
        let level = unsafe { optional_cstr(opts.log_level) };
        if let Err(e) = fff::log::init_tracing(log_path, level, None) {
            return FffResult::err(&format!("Failed to init tracing: {}", e));
        }
    }

    let frecency_path = unsafe { optional_cstr(opts.frecency_db_path) }.map(|s| s.to_string());
    let history_path = unsafe { optional_cstr(opts.history_db_path) }.map(|s| s.to_string());

    let shared_picker = SharedFilePicker::default();
    let shared_frecency = SharedFrecency::default();
    let query_tracker = SharedQueryTracker::default();

    if let Some(ref frecency_path) = frecency_path {
        if let Some(parent) = PathBuf::from(frecency_path).parent() {
            let _ = std::fs::create_dir_all(parent);
        }

        match FrecencyTracker::open(frecency_path) {
            Ok(tracker) => {
                if let Err(e) = shared_frecency.init(tracker) {

View on GitHub (pinned to 7f8537e70f)