Repository navigation
[#4] ISSUE-005: Command Execution Error Handling Gap - #15
Conversation
Reviewer's GuideAPIChange the public App command and navigation operations to return message-or-error results, so callers can handle failures consistently.
Replace the old command dispatcher with Result-based command handlers and centralized status reporting, including validation and external-command errors.
Uses of the APIRoute startup, save, and navigation outcomes through the shared result handler so their messages and errors reach the status bar.
ImplementationMove note-loading and file-collection helpers into App and update their callers to use the associated functions.
Remove edit-session snapshot and commit calls from mode transitions and visual edits.
TestsReplace and expand App tests to cover result reporting, command validation, save and navigation failures, source switches, startup outcomes, and external-command errors.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
Linked issuesChecked at commit f73440f #4 ISSUE-005: Command Execution Error Handling Gap · 2 of 3 met
|
There was a problem hiding this comment.
Hey - I've found 9 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/app.rs" line_range="205" />
<code_context>
/// DB の 1 ノートを開いて本文をバッファに載せる
- pub fn open_note_at_index(&mut self, idx: usize) {
+ pub fn open_note_at_index(&mut self, idx: usize) -> Result<String, String> {
if idx >= self.notes.len() {
- return;
</code_context>
<issue_to_address>
**Failed reads open blank notes**
When the selected note is missing, its content query fails, or the database file is removed before navigation, `Connection::open` creates a missing database, and `open_note_at_index` converts content-query errors with `unwrap_or_default()` into an “opened” success. The caller sees a blank note instead of the read error and can overwrite its content.
Open the database without creating it and propagate content-query errors from `open_note_at_index`.
Also at `src/app.rs:214-216`, `src/app.rs:236`, `src/app.rs:976`.
</issue_to_address>
### Comment 2
<location path="src/app.rs" line_range="973-977" />
<code_context>
+ return Err(format!("Invalid path: {}", p));
+ }
+ let notes = load_notes(&path).map_err(|e| e.to_string())?;
+ self.source = Source::Db(path.clone());
+ self.notes = notes;
+ if !self.notes.is_empty() {
+ self.open_note_at_index(0)?;
+ Ok(format!("db -> {}", path.display()))
+ } else {
+ Ok(format!("db -> {}. {}", path.display(), self.new_note()))
</code_context>
<issue_to_address>
**Source switches discard unsaved edits**
When the current document is modified and the user runs `:db` or `:dir`, `cmd_db` and `cmd_dir` replace the current document via `open_note_at_index`, `open_file_at_index`, or `new_note` without checking `doc.modified`, so the source switch succeeds and the caller’s unsaved edits disappear.
Reject these switches while modified, or require an explicit discard/override confirmation before replacing the document.
Also at `src/app.rs:997-1001`.
</issue_to_address>
### Comment 3
<location path="src/app.rs" line_range="973" />
<code_context>
+ return Err(format!("Invalid path: {}", p));
+ }
+ let notes = load_notes(&path).map_err(|e| e.to_string())?;
+ self.source = Source::Db(path.clone());
+ self.notes = notes;
+ if !self.notes.is_empty() {
</code_context>
<issue_to_address>
**Failed switches leave mixed state**
When opening the selected note or file fails after the target has been validated or listed, `cmd_db` and `cmd_dir` update `source`, their note or file lists, and `root_dir` before opening the selected document; the open error leaves the new source active with the previous document still loaded. The caller sees a failed command and a partially switched app.
Stage the target source, lists, and document, and commit them only after the selected item opens successfully.
Also at `src/app.rs:997-1001`.
</issue_to_address>
### Comment 4
<location path="src/app.rs" line_range="109" />
<code_context>
app.refresh();
- app.open_initial();
+ let initial_result = app.open_initial();
+ app.apply_command_result(initial_result);
Ok(app)
</code_context>
<issue_to_address>
**Startup database errors get hidden**
When loading the configured database fails during application startup, `refresh_notes` records a database-load error, but `open_initial` treats the resulting empty note list as an empty database and returns “New note created”; `apply_command_result` replaces the load error, so startup presents a successful state instead of the database failure.
Propagate the refresh failure into startup initialization and avoid replacing it with the empty-database success message.
</issue_to_address>
### Comment 5
<location path="src/app.rs" line_range="137-145" />
<code_context>
}
}
+ /// DB からノート一覧を読み出す(副作用なし)。
+ fn load_notes(path: &Path) -> anyhow::Result<Vec<NoteEntry>> {
+ let conn = Connection::open(path)?;
+ conn.execute(
+ "CREATE TABLE IF NOT EXISTS notes (\
+ id TEXT PRIMARY KEY, title TEXT NOT NULL DEFAULT '', \
+ content TEXT NOT NULL DEFAULT '', updatedAt INTEGER NOT NULL DEFAULT 0)",
+ rusqlite::params![],
+ )?;
+ let mut stmt = conn
+ .prepare("SELECT id, title, updatedAt FROM notes ORDER BY updatedAt DESC, id DESC")?;
</code_context>
<issue_to_address>
**Note loading creates database state**
When a caller uses `load_notes` expecting it only to read an existing database, `load_notes` is documented as having no side effects, but it opens the database and executes `CREATE TABLE IF NOT EXISTS`. Callers relying on the documented behavior can create a database or schema simply by loading notes.
Remove the schema creation from `load_notes` and initialize the schema separately, or document that loading may create the database and table.
</issue_to_address>
### Comment 6
<location path="src/app.rs" line_range="165" />
<code_context>
+ /// ディレクトリ内の md/txt ファイルを収集する(副作用なし)。
+ fn collect_files(dir: &Path) -> Vec<PathBuf> {
+ let mut list = Vec::new();
+ if let Ok(entries) = fs::read_dir(dir) {
+ for entry in entries.flatten() {
+ let path = entry.path();
</code_context>
<issue_to_address>
**Unreadable directories look empty**
When the target path is a directory but reading its entries fails, `collect_files` discards a `read_dir` error and returns an empty list; `cmd_dir` then switches to that directory and creates a new note, so the caller sees a successful switch to an empty directory.
Return a `Result` from `collect_files` and propagate directory-read errors before switching sources.
</issue_to_address>
### Comment 7
<location path="src/app.rs" line_range="1263-1264" />
<code_context>
+ let msg = app.status_message.as_ref().unwrap();
+ assert!(msg.contains("written"));
+ assert!(app.files.len() >= 1);
+ assert!(!app.doc.modified);
+ }
+
+ #[test]
</code_context>
<issue_to_address>
**Write-and-quit can skip saving**
When the `wq` implementation quits and clears `doc.modified` without writing, `wq_saves_then_quits` checks only `should_quit` and `doc.modified` at `src/app.rs:1261-1263`; it passes if `wq` clears the modified flag and quits without persisting the buffer.
Assert that the buffer contents were persisted before verifying that the app quits.
</issue_to_address>
### Comment 8
<location path="src/app.rs" line_range="1430-1431" />
<code_context>
+ fs::File::create(&blocker).unwrap();
+ let mut app = App::new(Source::Dir(dir.clone()), dir.clone()).unwrap();
+ let original_source = app.source.clone();
+ app.execute_command("db notadb");
+ assert_eq!(app.source, original_source);
+ let msg = app.status_message.as_ref().unwrap();
+ assert!(msg.starts_with("Error:"));
</code_context>
<issue_to_address>
**Relative fixtures target wrong directory**
When the tests run from a working directory different from their temporary fixture directories, `db_invalid_target_does_not_change_source`, `dir_invalid_path_does_not_change_source`, and `dir_regular_file_does_not_change_source` pass relative names at `src/app.rs:1430-1431`, `1466-1467`, and `1478-1480`, not paths to their temporary fixtures. The commands operate relative to the process working directory, so `db` can open/create a database and `dir` can create or switch to a directory there; the source assertions then fail.
Pass absolute fixture paths in these commands, or explicitly resolve the relative arguments against the temporary directory.
Also at `src/app.rs:1466-1467`, `src/app.rs:1479-1480`.
</issue_to_address>
### Comment 9
<location path="src/app.rs" line_range="1287" />
<code_context>
+# Ignore everything by default
+*
+
+# This file itself
+!.gitignore
</code_context>
<issue_to_address>
**Modified-buffer guard tests fail**
When the modified-buffer guards reject the commands without copying the buffer into `doc.body`, when `e` or `new` correctly rejects a modified buffer, `e_rejects_when_modified` and `new_rejects_when_modified` compare `app.doc.body` to `"changed"` at `src/app.rs:1285` and `1333`. The tests set `app.buffer`, not `doc.body`, so those assertions fail even though the buffer was preserved.
Assert that `app.buffer.to_string()` is still `"changed"`, or initialize `doc.body` consistently with the buffer before the command.
Also at `src/app.rs:1333`.
</issue_to_address>Sourcery assessment
Approval pending. 8 findings to address first.
Blocking findings: src/app.rs:205, src/app.rs:977, src/app.rs:973, src/app.rs:109, src/app.rs:165, and 3 more
| self.source = Source::Db(path.clone()); | ||
| self.notes = notes; | ||
| if !self.notes.is_empty() { | ||
| self.open_note_at_index(0)?; | ||
| Ok(format!("db -> {}", path.display())) |
There was a problem hiding this comment.
🟠 High · Source switches discard unsaved edits
When the current document is modified and the user runs :db or :dir, cmd_db and cmd_dir replace the current document via open_note_at_index, open_file_at_index, or new_note without checking doc.modified, so the source switch succeeds and the caller’s unsaved edits disappear.
Reject these switches while modified, or require an explicit discard/override confirmation before replacing the document.
Also at src/app.rs:997-1001.
Prompt for AI agents
In `src/app.rs` at lines 973-977:
**Source switches discard unsaved edits**
When the current document is modified and the user runs `:db` or `:dir`, `cmd_db` and `cmd_dir` replace the current document via `open_note_at_index`, `open_file_at_index`, or `new_note` without checking `doc.modified`, so the source switch succeeds and the caller’s unsaved edits disappear.
Reject these switches while modified, or require an explicit discard/override confirmation before replacing the document.
Also at `src/app.rs:997-1001`.| return Err(format!("Invalid path: {}", p)); | ||
| } | ||
| let notes = load_notes(&path).map_err(|e| e.to_string())?; | ||
| self.source = Source::Db(path.clone()); |
There was a problem hiding this comment.
🟡 Medium · Failed switches leave mixed state
When opening the selected note or file fails after the target has been validated or listed, cmd_db and cmd_dir update source, their note or file lists, and root_dir before opening the selected document; the open error leaves the new source active with the previous document still loaded. The caller sees a failed command and a partially switched app.
Stage the target source, lists, and document, and commit them only after the selected item opens successfully.
Also at src/app.rs:997-1001.
Prompt for AI agents
In `src/app.rs` at line 973:
**Failed switches leave mixed state**
When opening the selected note or file fails after the target has been validated or listed, `cmd_db` and `cmd_dir` update `source`, their note or file lists, and `root_dir` before opening the selected document; the open error leaves the new source active with the previous document still loaded. The caller sees a failed command and a partially switched app.
Stage the target source, lists, and document, and commit them only after the selected item opens successfully.
Also at `src/app.rs:997-1001`.From #4:
Add validation before mode transitions.| app.refresh(); | ||
| app.open_initial(); | ||
| let initial_result = app.open_initial(); | ||
| app.apply_command_result(initial_result); |
There was a problem hiding this comment.
🟡 Medium · Startup database errors get hidden
When loading the configured database fails during application startup, refresh_notes records a database-load error, but open_initial treats the resulting empty note list as an empty database and returns “New note created”; apply_command_result replaces the load error, so startup presents a successful state instead of the database failure.
Propagate the refresh failure into startup initialization and avoid replacing it with the empty-database success message.
Prompt for AI agents
In `src/app.rs` at line 109:
**Startup database errors get hidden**
When loading the configured database fails during application startup, `refresh_notes` records a database-load error, but `open_initial` treats the resulting empty note list as an empty database and returns “New note created”; `apply_command_result` replaces the load error, so startup presents a successful state instead of the database failure.
Propagate the refresh failure into startup initialization and avoid replacing it with the empty-database success message.| /// DB からノート一覧を読み出す(副作用なし)。 | ||
| fn load_notes(path: &Path) -> anyhow::Result<Vec<NoteEntry>> { | ||
| let conn = Connection::open(path)?; | ||
| conn.execute( | ||
| "CREATE TABLE IF NOT EXISTS notes (\ | ||
| id TEXT PRIMARY KEY, title TEXT NOT NULL DEFAULT '', \ | ||
| content TEXT NOT NULL DEFAULT '', updatedAt INTEGER NOT NULL DEFAULT 0)", | ||
| rusqlite::params![], | ||
| )?; |
There was a problem hiding this comment.
⚪ Low · Note loading creates database state
When a caller uses load_notes expecting it only to read an existing database, load_notes is documented as having no side effects, but it opens the database and executes CREATE TABLE IF NOT EXISTS. Callers relying on the documented behavior can create a database or schema simply by loading notes.
Remove the schema creation from load_notes and initialize the schema separately, or document that loading may create the database and table.
Prompt for AI agents
In `src/app.rs` at lines 137-145:
**Note loading creates database state**
When a caller uses `load_notes` expecting it only to read an existing database, `load_notes` is documented as having no side effects, but it opens the database and executes `CREATE TABLE IF NOT EXISTS`. Callers relying on the documented behavior can create a database or schema simply by loading notes.
Remove the schema creation from `load_notes` and initialize the schema separately, or document that loading may create the database and table.| /// ディレクトリ内の md/txt ファイルを収集する(副作用なし)。 | ||
| fn collect_files(dir: &Path) -> Vec<PathBuf> { | ||
| let mut list = Vec::new(); | ||
| if let Ok(entries) = fs::read_dir(dir) { |
There was a problem hiding this comment.
🟡 Medium · Unreadable directories look empty
When the target path is a directory but reading its entries fails, collect_files discards a read_dir error and returns an empty list; cmd_dir then switches to that directory and creates a new note, so the caller sees a successful switch to an empty directory.
Return a Result from collect_files and propagate directory-read errors before switching sources.
Prompt for AI agents
In `src/app.rs` at line 165:
**Unreadable directories look empty**
When the target path is a directory but reading its entries fails, `collect_files` discards a `read_dir` error and returns an empty list; `cmd_dir` then switches to that directory and creates a new note, so the caller sees a successful switch to an empty directory.
Return a `Result` from `collect_files` and propagate directory-read errors before switching sources.| assert!(!app.doc.modified); | ||
| } |
There was a problem hiding this comment.
🟡 Medium · Write-and-quit can skip saving
When the wq implementation quits and clears doc.modified without writing, wq_saves_then_quits checks only should_quit and doc.modified at src/app.rs:1261-1263; it passes if wq clears the modified flag and quits without persisting the buffer.
Assert that the buffer contents were persisted before verifying that the app quits.
Prompt for AI agents
In `src/app.rs` at lines 1263-1264:
**Write-and-quit can skip saving**
When the `wq` implementation quits and clears `doc.modified` without writing, `wq_saves_then_quits` checks only `should_quit` and `doc.modified` at `src/app.rs:1261-1263`; it passes if `wq` clears the modified flag and quits without persisting the buffer.
Assert that the buffer contents were persisted before verifying that the app quits.… matter + e! missing-file check
…rrors, buffer-based reject assertions
Summary
Issue-005: Command Execution Error Handling Gap
Problem: The
execute_commandmethod has inconsistent error reporting - some commands updatestatus_messagewhile others silently fail or produce terminal output only.Evidence:
:w(save) updates status on success/failure:qshows message only if modified, otherwise setsshould_quit:dband:dirshow usage message if arg missing, but don't prevent mode switchSuggested Fix:
Execution Report
Workflow
simple-minicompleted successfully.Closes #4
Summary by Sourcery
Unify command execution results and validation so operations consistently report errors, preserve state on failure, and return the editor to Normal mode.
Bug Fixes:
Enhancements:
Tests: