diff --git a/crates/edit_prediction_cli/src/main.rs b/crates/edit_prediction_cli/src/main.rs index d84541af456d3c15d820532b32e9509ddb330e74..c7128fdefc2dc96e0cc131525771aeb94ea907d1 100644 --- a/crates/edit_prediction_cli/src/main.rs +++ b/crates/edit_prediction_cli/src/main.rs @@ -470,9 +470,12 @@ fn main() { return; } Command::SplitCommit(split_commit_args) => { - if let Err(error) = - split_commit::run_split_commit(split_commit_args, &args.inputs, output.as_ref()) - { + if let Err(error) = split_commit::run_split_commit( + split_commit_args, + &args.inputs, + output.as_ref(), + args.failed, + ) { eprintln!("{error:#}"); std::process::exit(1); } diff --git a/crates/edit_prediction_cli/src/split_commit.rs b/crates/edit_prediction_cli/src/split_commit.rs index b4c381193d45fc14040ea281bd8dac7bf2507c70..a992f1af7183d12477d9e19642c7f27dfb3c4b44 100644 --- a/crates/edit_prediction_cli/src/split_commit.rs +++ b/crates/edit_prediction_cli/src/split_commit.rs @@ -4,6 +4,7 @@ //! chronologically-ordered unified diff (a "commit"). //! //! TODO: Port Python code to generate chronologically-ordered commits +use crate::FailedHandling; use crate::reorder_patch::{Patch, PatchLine, extract_edits, locate_edited_line}; /// Find the largest valid UTF-8 char boundary at or before `index` in `s`. @@ -116,6 +117,7 @@ pub fn run_split_commit( args: &SplitCommitArgs, inputs: &[PathBuf], output_path: Option<&PathBuf>, + failed: FailedHandling, ) -> Result<()> { use std::collections::HashSet; use std::io::BufRead; @@ -158,22 +160,34 @@ pub fn run_split_commit( for sample_idx in 0..num_samples { let sample_seed = base_seed.wrapping_add(sample_idx as u64); - let case = generate_evaluation_example_from_ordered_commit( + let case = match generate_evaluation_example_from_ordered_commit( &annotated.reordered_commit, &annotated.repo_url, &annotated.commit_sha, None, // Use random split point for multi-sample mode Some(sample_seed), Some(sample_idx), - ) - .with_context(|| { - format!( - "failed to generate evaluation example for commit {} at line {} (sample {})", - annotated.commit_sha, - line_num + 1, - sample_idx - ) - })?; + ) { + Ok(case) => case, + Err(e) => { + let err_msg = format!( + "failed to generate evaluation example for commit {} at line {} (sample {}): {}", + annotated.commit_sha, + line_num + 1, + sample_idx, + e + ); + match failed { + FailedHandling::Skip => { + eprintln!("{}", err_msg); + continue; + } + FailedHandling::Keep => { + anyhow::bail!(err_msg); + } + } + } + }; let json = if args.pretty { serde_json::to_string_pretty(&case) @@ -188,21 +202,33 @@ pub fn run_split_commit( } } } else { - let case = generate_evaluation_example_from_ordered_commit( + let case = match generate_evaluation_example_from_ordered_commit( &annotated.reordered_commit, &annotated.repo_url, &annotated.commit_sha, split_point.clone(), args.seed, None, - ) - .with_context(|| { - format!( - "failed to generate evaluation example for commit {} at line {}", - annotated.commit_sha, - line_num + 1 - ) - })?; + ) { + Ok(case) => case, + Err(e) => { + let err_msg = format!( + "failed to generate evaluation example for commit {} at line {}: {}", + annotated.commit_sha, + line_num + 1, + e + ); + match failed { + FailedHandling::Skip => { + eprintln!("{}", err_msg); + continue; + } + FailedHandling::Keep => { + anyhow::bail!(err_msg); + } + } + } + }; let json = if args.pretty { serde_json::to_string_pretty(&case)