Skip to content

fix(cli): avoid ENOTDIR when scanning a single file - #148

Merged
isasmendiagus merged 2 commits into
mainfrom
fix/scan-single-file-settings-lookup
Jun 5, 2026
Merged

fix(cli): avoid ENOTDIR when scanning a single file#148
isasmendiagus merged 2 commits into
mainfrom
fix/scan-single-file-settings-lookup

Conversation

@isasmendiagus

@isasmendiagus isasmendiagus commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator

Summary

scanoss-js scan <file> crashed with ENOTDIR when the scan target was a single file instead of a directory:

Error: ENOTDIR: not a directory, scandir '/storage/Users/currentUser/user-agreement.pdf'
    at async getSettingsFilePath (.../cli/commands/helpers.js:35:19)
    at async scanHandler (.../cli/commands/scan.js:127:34)

The automatic scanoss.json settings lookup (introduced in SP-1996) called fs.promises.readdir() directly on the scan target without checking whether it was a directory, so single-file scans crashed before the scan even started.

Changes

  • getSettingsFilePath() now stats the path first; for single files it looks for the default scanoss.json in the file's parent directory instead of calling readdir on the file itself.
  • Added helpers.spec.ts with 5 tests covering the settings lookup, including the ENOTDIR regression case.
  • Bumped version to 0.40.1 and updated CHANGELOG.

Test plan

  • npm test — 177 passing (172 existing + 5 new)
  • npm run build

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Fixed an issue where scanning a single file with scanoss-js scan <file> failed with an ENOTDIR error. The settings lookup now correctly resolves to the file's parent directory.
  • Version

    • Released version 0.40.1

isasmendiagus and others added 2 commits June 5, 2026 09:22
The automatic scanoss.json settings lookup called readdir directly on
the scan target, crashing with ENOTDIR when the target was a single
file instead of a directory. Now it stats the path first and resolves
the parent directory for single files.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 5, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 201f80c4-8788-4409-acf9-d2de109740f2

📥 Commits

Reviewing files that changed from the base of the PR and between ae75223 and 5859cae.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (4)
  • CHANGELOG.md
  • package.json
  • src/cli/commands/helpers.spec.ts
  • src/cli/commands/helpers.ts

📝 Walkthrough

Walkthrough

This PR fixes a bug where scanning a single file with scanoss-js scan <file> fails with ENOTDIR error. The fix updates getSettingsFilePath to detect non-directory scan paths and resolve to the parent directory before searching for settings. Comprehensive tests cover the fix, and the package version is bumped to 0.40.1 with release notes.

Changes

Single-File Scan Bug Fix

Layer / File(s) Summary
Single-file scan fix and test coverage
src/cli/commands/helpers.ts, src/cli/commands/helpers.spec.ts
getSettingsFilePath now uses fs.promises.stat to detect whether scanPath is a directory; if not, it resolves to the parent directory (path.dirname) before calling readdir and searching for scanoss.json. Test suite verifies explicit paths, default settings discovery in directories and adjacent to single files, null when settings are absent, and no errors when scanning single files.
Version and release notes
package.json, CHANGELOG.md
Package version bumped to 0.40.1 with changelog entry documenting the fix for scanoss-js scan <file> ENOTDIR resolution.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested reviewers

  • scanoss-qg

Poem

🐰 A single file once caused despair,
With ENOTDIR floating through the air,
Now parent paths resolve with grace,
And scans succeed in any place! ✨

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/scan-single-file-settings-lookup

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@isasmendiagus
isasmendiagus merged commit 66d1ff2 into main Jun 5, 2026
3 of 4 checks passed
@isasmendiagus
isasmendiagus deleted the fix/scan-single-file-settings-lookup branch June 5, 2026 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant