{"record":{"id":"25a20ece6ac279d8","repo":"helix-editor/helix","slug":"expected-a-path-to-file-but-found-a-directory-f","errorCode":null,"errorMessage":"expected a path to file, but found a directory: {file:?}. (to open a directory pass it as first argument)","messagePattern":"expected a path to file, but found a directory: (.+?)\\. \\(to open a directory pass it as first argument\\)","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"helix-term/src/application.rs","lineNumber":164,"sourceCode":"            editor.open(&path, Action::VerticalSplit)?;\n            // Unset path to prevent accidentally saving to the original tutor file.\n            doc_mut!(editor).set_path(None);\n        } else if !args.files.is_empty() {\n            let mut files_it = args.files.into_iter().peekable();\n\n            // If the first file is a directory, skip it and open a picker\n            if let Some((first, _)) = files_it.next_if(|(p, _)| p.is_dir()) {\n                let picker = ui::file_picker(&editor, first);\n                compositor.push(Box::new(overlaid(picker)));\n            }\n\n            // If there are any more files specified, open them\n            if files_it.peek().is_some() {\n                let mut nr_of_files = 0;\n                for (file, pos) in files_it {\n                    nr_of_files += 1;\n                    if file.is_dir() {\n                        return Err(anyhow::anyhow!(\n                            \"expected a path to file, but found a directory: {file:?}. (to open a directory pass it as first argument)\"\n                        ));\n                    } else {\n                        // If the user passes in either `--vsplit` or\n                        // `--hsplit` as a command line argument, all the given\n                        // files will be opened according to the selected\n                        // option. If neither of those two arguments are passed\n                        // in, just load the files normally.\n                        let action = match args.split {\n                            _ if nr_of_files == 1 => Action::VerticalSplit,\n                            Some(Layout::Vertical) => Action::VerticalSplit,\n                            Some(Layout::Horizontal) => Action::HorizontalSplit,\n                            None => Action::Load,\n                        };\n                        let old_id = editor.document_id_by_path(&file);\n                        let doc_id = match editor.open(&file, action) {\n                            // Ignore irregular files during application init.\n                            Err(DocumentOpenError::IrregularFile) => {","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/helix-editor/helix/blob/079a789e8cb08ead67f19e1971a1b7438b37354b/helix-term/src/application.rs#L146-L182","documentation":"Command-line argument validation in Application::new: Helix allows exactly one leading directory (it opens a file picker for it); if any subsequent positional argument is a directory, startup aborts with this error instead of silently mis-opening it.","triggerScenarios":"Invoking 'hx dir_a file.txt dir_b' - the first directory becomes a picker, but the second directory (any non-first positional that is a dir) triggers the bail. Mixing directories into a file list in any position after the first argument.","commonSituations":"Shell glob or foil/expansion pulling directories into the file list (e.g. 'hx src/*' when subdirectories exist); scripts passing '$@' where one entry is a dir; muscle memory from editors that accept dirs anywhere ('code dir file dir').","solutions":["Pass the directory first and only once: 'hx <dir> <files...>' or open dirs in a separate invocation","Quote/expand carefully - use nullglob or filter expansions: 'hx $(find . -maxdepth 1 -type f)' style filtering, or zsh 'src/*(.)' glob qualifier for files only","If you meant to open a picker for each dir, run them one per invocation"],"exampleFix":"# before\nhx src/*          # src contains subdirs -> error for the 2nd directory\n\n# after\nhx src            # picker for the whole dir\nhx $(find src -maxdepth 1 -type f)   # files only","handlingStrategy":"validation","validationCode":"# Shell: filter out all but the first directory before invoking hx\nfirst_dir=\"\"; files=()\nfor p in \"$@\"; do\n  if [ -d \"$p\" ] && [ -z \"$first_dir\" ]; then first_dir=\"$p\"\n  elif [ ! -d \"$p\" ]; then files+=(\"$p\"); fi\ndone\nif [ -n \"$first_dir\" ]; then exec hx \"$first_dir\" \"${files[@]}\"; fi\nexec hx \"${files[@]}\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass at most one directory, and make it the FIRST argument","Filter globs to files (zsh: *(.) ; find -type f) before passing to hx","In scripts, canonicalize and classify args (dir/file) before building the command line"],"tags":["rust","helix","cli","args","filesystem"],"backgroundTag":null,"analyzedSha":"079a789e8cb08ead67f19e1971a1b7438b37354b","analyzedAt":"2026-08-16T09:09:59.668Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}