screenpipe/screenpipe · error
Failed to create valid path
Error message
Failed to create valid path
What it means
get_new_file_path_with_timestamp builds an output file path as output_path/device_timestamp.mp4 and calls .to_str().expect("Failed to create valid path"). PathBuf::to_str returns None only when the path is not valid UTF-8, so this panics when the output directory or device name contains non-UTF-8 bytes.
Source
Thrown at crates/screenpipe-audio/src/utils/ffmpeg.rs:156
drop(stdin);
debug!("Waiting for FFmpeg process to exit");
child
.wait_with_output()
.map_err(|e| anyhow::anyhow!("FFmpeg wait failed: {e}"))
}
pub fn get_new_file_path_with_timestamp(
device: &str,
output_path: &PathBuf,
capture_time: Option<DateTime<Utc>>,
) -> String {
let ts = capture_time.unwrap_or_else(Utc::now);
let new_file_name = ts.format("%Y-%m-%d_%H-%M-%S").to_string();
let sanitized_device_name = device.replace(['/', '\\'], "_");
PathBuf::from(output_path)
.join(format!("{}_{}.mp4", sanitized_device_name, new_file_name))
.to_str()
.expect("Failed to create valid path")
.to_string()
}
/// Decode an audio file (MP4/AAC) back to 16kHz mono f32 PCM using ffmpeg.
/// Returns (samples, sample_rate).
pub fn read_audio_from_file(path: &Path) -> Result<(Vec<f32>, u32)> {
let sample_rate: u32 = 16000;
let ffmpeg_path = find_ffmpeg_path()
.ok_or_else(|| anyhow::anyhow!("ffmpeg not found in PATH or bundled binaries"))?;
let path_str = path
.to_str()
.ok_or_else(|| anyhow::anyhow!("path is not valid UTF-8: {}", path.display()))?;
let mut command = screenpipe_core::ffmpeg_cmd(ffmpeg_path);
command
.args([
"-i",View on GitHub (pinned to 4ebf712990)
Solutions
- sanitize device names to ASCII/valid-UTF-8 characters instead of only replacing slashes
- use .to_string_lossy().into_owned() or propagate an error instead of .expect
- validate output_path is valid UTF-8 at configuration load time
Example fix
// before
.to_str().expect("Failed to create valid path").to_string()
// after
.to_str()
.map(str::to_string)
.ok_or_else(|| anyhow!("output path is not valid UTF-8: {:?}", output_path))? Defensive patterns
Strategy: validation
Validate before calling
fn ensure_utf8_path(p: &Path) -> Result<(), anyhow::Error> {
p.to_str().map(|_| ()).ok_or_else(|| anyhow!("path {:?} is not valid UTF-8", p))
} Type guard
fn is_utf8_path(p: &Path) -> bool { p.to_str().is_some() } Try / catch
let path_str = path_buf.to_str()
.ok_or_else(|| anyhow!("output path not valid UTF-8: {:?}", path_buf))?; Prevention
- sanitize device names to a safe ASCII charset (alnum, dash, underscore), not just slashes
- validate configured output directories for UTF-8 validity at startup
- prefer to_string_lossy or Result propagation over .expect on to_str
When it happens
Trigger: output_path configured to a directory with non-UTF-8 bytes (e.g. non-ASCII filesystem encoding) or an audio device whose name contains non-UTF-8 characters that survive sanitization (the sanitizer only replaces '/' and '\\').
Common situations: devices with emoji/unicode names on odd filesystems; Windows paths with unusual encodings; user-configured output dirs from env vars with invalid bytes.
Related errors
- cannot determine parent dir of {:?}
- extracted frame has no filename
- Failed to create valid path
- createProvider: a non-empty model string is required
- mlx transcription panic (likely Metal GPU error): {}
AI-assisted analysis of screenpipe/screenpipe@4ebf712990 (2026-09-01).
Data as JSON: /api/errors/3757711f30294560.
Report an issue: GitHub.