Skip to content

Conversation

@vlad-ivanov-name
Copy link
Collaborator

This commit addresses the unresolved review comments from the merged PR that added the josh CLI tool:

Error Handling Improvements

  • Add anyhow and thiserror to workspace dependencies
  • Replace Box with anyhow::Result throughout josh-cli
  • Use anyhow::Context for better error messages with context

josh-core/src/changes.rs Improvements

  • Use into_iter() instead of iter() where changes vec is consumed
  • Replace manual indexing with .windows(2) for cleaner iteration
  • Use iterator chaining with base_tree for tree collection
  • Use HashSet::insert() which returns false for duplicates
  • Improve variable naming: old -> base_oid, v -> push_refs
  • Change ref_with_options parameter from String to &str for consistency
  • Replace if let with match for better pattern matching
  • Use filter_map instead of filter + map

josh-cli/src/bin/josh.rs Improvements

  • Remove all std::env::set_current_dir() calls (hacky global state)
  • Create internal helper functions that accept repo_path parameter:
    • handle_fetch_internal(args, repo_path)
    • handle_remote_add_internal(args, repo_path)
    • handle_filter_internal(args, repo_path, print_messages)
    • apply_josh_filtering(repo_path, filter, remote_name)
  • Remove commented out code
  • Update all error handling to use anyhow::Context
  • Fix build_to_push call to pass &remote_ref instead of remote_ref

🤖 Generated with Claude Code

@vlad-ivanov-name
Copy link
Collaborator Author

@claude address review feedback

@claude
Copy link

claude bot commented Nov 11, 2025

Claude Code is working…

I'll analyze this and get back to you.

View job run

@claude
Copy link

claude bot commented Nov 11, 2025

Claude finished @vlad-ivanov-name's task —— View job


Addressing Review Feedback

All review comments have been addressed! ✅

  • Read changed files to understand current code
  • Remove unused dependency from Cargo.toml
  • Create from_josh_err helper function for error mapping
  • Replace bail! macro with explicit return statements
  • Verify changes compile
  • Commit and push changes

Changes Made

  1. Removed unused thiserror dependency from Cargo.toml:38 workspace dependencies
  2. Created from_josh_err helper function at josh-cli/src/bin/josh.rs:12 to convert josh::JoshError to anyhow::Error
  3. Replaced all manual error mapping with .map_err(from_josh_err).context("...") pattern:
    • josh-cli/src/bin/josh.rs:285 - filter parsing in apply_josh_filtering
    • josh-cli/src/bin/josh.rs:295 - NotesCacheBackend creation (2 occurrences)
    • josh-cli/src/bin/josh.rs:301 - TransactionContext operations (2 occurrences)
    • josh-cli/src/bin/josh.rs:660 - filter parsing in handle_push
    • josh-cli/src/bin/josh.rs:802 - unapply_filter call
    • josh-cli/src/bin/josh.rs:822 - build_to_push call
  4. Replaced all 7 instances of bail! macro with explicit return Err(anyhow::anyhow!(...)) statements for clearer control flow at lines: 368, 461, 481, 580, 864, 950, 968

The changes improve error handling clarity and avoid hidden control flow as requested.

--- |

@christian-schilling
Copy link
Member

@claude fix the failing build

@claude
Copy link

claude bot commented Nov 11, 2025

Claude finished @christian-schilling's task —— View job


Build Failure Fixed

All formatting errors have been resolved! ✅

  • Check CI status to understand what's failing
  • Identify root cause: cargo fmt formatting errors
  • Apply formatting fixes to all affected files
  • Commit and push changes

Changes Made

Fixed Rust formatting errors in josh-cli/src/bin/josh.rs and josh-core/src/changes.rs:

  • Consolidated function parameters onto single lines where appropriate
  • Removed extra blank lines
  • Formatted multi-line error messages consistently
  • Applied proper rustfmt style to chained method calls

The build should now pass the cargo fmt --check step. The changes have been pushed to the branch.
| Latest commit

@vlad-ivanov-name vlad-ivanov-name force-pushed the claude/pr-1518-20251111-0248 branch from 29e9c96 to 08fa777 Compare November 12, 2025 04:07
This commit addresses the unresolved review comments from the merged PR
that added the josh CLI tool:

## Error Handling Improvements
- Add anyhow and thiserror to workspace dependencies
- Replace Box<dyn std::error::Error> with anyhow::Result throughout josh-cli
- Use anyhow::Context for better error messages with context

## josh-core/src/changes.rs Improvements
- Use into_iter() instead of iter() where changes vec is consumed
- Replace manual indexing with .windows(2) for cleaner iteration
- Use iterator chaining with base_tree for tree collection
- Use HashSet::insert() which returns false for duplicates
- Improve variable naming: old -> base_oid, v -> push_refs
- Change ref_with_options parameter from String to &str for consistency
- Replace if let with match for better pattern matching
- Use filter_map instead of filter + map

## josh-cli/src/bin/josh.rs Improvements
- Remove all std::env::set_current_dir() calls (hacky global state)
- Create internal helper functions that accept repo_path parameter:
  - handle_fetch_internal(args, repo_path)
  - handle_remote_add_internal(args, repo_path)
  - handle_filter_internal(args, repo_path, print_messages)
  - apply_josh_filtering(repo_path, filter, remote_name)
- Remove commented out code
- Update all error handling to use anyhow::Context
- Fix build_to_push call to pass &remote_ref instead of remote_ref

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Vlad Ivanov <vlad-ivanov-name@users.noreply.github.com>
@vlad-ivanov-name vlad-ivanov-name force-pushed the claude/pr-1518-20251111-0248 branch from 08fa777 to eb2aa0b Compare November 12, 2025 04:23
@vlad-ivanov-name vlad-ivanov-name marked this pull request as ready for review November 12, 2025 06:19
Copy link
Member

@christian-schilling christian-schilling left a comment

Choose a reason for hiding this comment

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

I think josh.rs looks a lot better with those changes. changes.rs not so much.

if let Some(id) = &change.id {
if id.contains('@') {
return Err(josh_error("Change id must not contain '@'"));
match &change.id {

Choose a reason for hiding this comment

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

I really prefer if let over match in cases where only one of the cases needs data. It's easier to type due to less special characters and easier to read do to less nesting.

if push_mode == PushMode::Review {
v.push((
ref_with_options.clone(),
match changes {

Choose a reason for hiding this comment

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

Same, I think if let is better.

.map(|(_, commit, _)| repo.find_commit(*commit))
.collect::<Result<Vec<_>, _>>()?;

let base_tree = std::iter::once(repo.find_commit(base)?.tree()?);

Choose a reason for hiding this comment

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

I don't particularly like the changed version since it has two more concepts (this "iter once" and interator chaining) and more indentation than the old one.
Maybe it could be better to do the map over all commits first and then have the commit -> tree just once. (keeping the once + chain, but i think it would still be simpler)

eprintln!("Error: {}", e);
std::process::exit(1);
}
let result = match &cli.command {

Choose a reason for hiding this comment

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

Oh, this is a lot better! :)

@christian-schilling
Copy link
Member

@claude address review feedback

@claude
Copy link

claude bot commented Nov 12, 2025

Claude finished @christian-schilling's task —— View job


Addressing Review Feedback

All review feedback has been addressed! ✅

  • Read josh-core/src/changes.rs to understand current code
  • Change match back to if let at line 125
  • Change match back to if let at line 175
  • Simplify iterator chaining at line 57
  • Commit and push changes

Changes Made

  1. Reverted match to if let at line 125 - The pattern matching for change.id is now using if let Some(id) with an else block, which is cleaner and easier to read when only one case needs the data.

  2. Reverted match to if let at line 175 - The pattern matching for changes in build_to_push function now uses if let Some(changes) with an else block for better readability.

  3. Simplified iterator chaining at line 57 - Instead of using std::iter::once + chain, the code now:

    • Creates a vec! with the base tree
    • Uses .extend() to add the commit trees
    • This is simpler with fewer concepts (no iterator chaining) and less indentation

These changes improve code readability while maintaining the same functionality. The changes have been pushed to the PR branch.
| Latest commit

- Change match back to if let at lines 125 and 175 (cleaner for single-data-case patterns)
- Simplify iterator chaining at line 57 (use vec with extend instead of iter::once + chain)

Co-authored-by: Christian Schilling <christian-schilling@users.noreply.github.com>
@christian-schilling
Copy link
Member

@claude fix the failed build

@claude
Copy link

claude bot commented Nov 12, 2025

Claude finished @christian-schilling's task —— View job


Build Failure Fixed

All formatting issues have been resolved! ✅

  • Check CI status to understand what's failing
  • Fix formatting issue in josh-core/src/changes.rs (line 58 was too long)
  • Commit and push changes

Changes Made

Fixed Rust formatting error in josh-core/src/changes.rs:58 - the line calling trees.extend() exceeded the line length limit and has been reformatted to split across multiple lines for better readability.

The build should now pass the cargo fmt --check step. The changes have been pushed to the branch.
| Latest commit

The line calling trees.extend() exceeded the line length limit.
Reformatted to split across multiple lines for better readability.

Co-authored-by: Christian Schilling <christian-schilling@users.noreply.github.com>
@christian-schilling christian-schilling added this pull request to the merge queue Nov 12, 2025
Merged via the queue into master with commit 1fa2684 Nov 12, 2025
1 check passed
@christian-schilling christian-schilling deleted the claude/pr-1518-20251111-0248 branch November 12, 2025 17:17
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.

3 participants