Skip to content

fix: say a token or database path that names a directory is one - #174

Merged
drakulavich merged 3 commits into
mainfrom
fix/dir-paths
Oct 25, 2026
Merged

drakulavich merged 3 commits into
mainfrom
fix/dir-paths

Conversation

@drakulavich

Copy link
Copy Markdown
Owner

Closes #149, closes #151.

What

Why

Both reproduced on main (0.9.1 sources):

  • login --token x --path <dir> printed error: EISDIR: illegal operation on a directory, open '<dir>', exit 1, no hint.
  • OURA_DB_PATH=<dir> oura-cli db today gave unable to open database file with the hint about write permissions on the file and its directory.

How checked

🤖 Generated with Claude Code

https://claude.ai/code/session_018qh9xqviBHYmzVtmQWSKqA

drakulavich and others added 2 commits October 25, 2026 14:10
…SDIR

writeFileSync's EISDIR escaped login's catch as a plain Error, so the user
got Node's message and no hint. writeToken now turns it into a BAD_ARGS
CliError that names the path and suggests a file inside it.

Closes #149

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018qh9xqviBHYmzVtmQWSKqA
…rmissions problem

SQLite reports a directory as "unable to open database file", which the
hint table maps to the permissions hint. openDatabase now checks for a
directory before it opens and names it in the error.

Closes #151

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018qh9xqviBHYmzVtmQWSKqA
@drakulavich

Copy link
Copy Markdown
Owner Author

Codex review (gpt-6-luna, final, ebcf1cc..4463700):

Reviewed c20fd75^..4463700. The directory checks and error hints match the brief; I found no Critical or Required issues.

The touched tests passed: 31 tests across src/commands/login.test.ts and src/db/open.test.ts.

Simplification: not needed

Verdict: Approve

@greptile-apps

greptile-apps Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with two non-blocking findings from the previous review still open.

Findings

  1. P2 Correct hints fail Windows tests ▶
  2. P2 File checks bypass database errors ▶

Summary

The PR gives clearer errors when a token or database path names a directory.

  • Login points out when its token path is a directory.
  • Database paths that name directories get a file-path suggestion.

Reviews (2) · Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." · Reviewed by Greptile

Comment thread src/db/open.test.ts
expect({ code: (err as CliError).code, message: (err as CliError).message, hint: (err as CliError).hint }).toEqual({
code: 'DB_ERROR',
message: `Cannot open database ${target}: it is a directory.`,
hint: `Point --db / OURA_DB_PATH at a file, such as ${target}/oura.db.`,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Correct hints fail Windows tests

The new tests expect / before the example filename, but both functions build their hints with join, which uses backslashes on Windows. These exact checks fail even when the returned hint is correct. Use join(target, 'oura.db') here and join(dir, '.oura-token') in src/commands/login.test.ts.

Comment thread src/db/open.ts

export function openDatabase(explicit?: string): Database {
const dbPath = getDbPath(explicit);
if (dbPath !== ':memory:' && existsSync(dbPath) && statSync(dbPath).isDirectory()) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 File checks bypass database errors

statSync now runs outside the error wrapper. If another process removes the database after existsSync succeeds—for example, while rebuilding the cache—statSync throws a raw file error. Commands then report UNKNOWN with exit code 1 instead of DB_ERROR with exit code 4, and doctor loses the hint. Keep file checks inside the wrapper while preserving the directory-specific CliError.

@drakulavich
drakulavich merged commit 3fbc541 into main Oct 25, 2026
2 checks passed
@drakulavich
drakulavich deleted the fix/dir-paths branch October 25, 2026 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant