@@ -19,7 +19,7 @@ export function changeFile(
1919 const fileChange = FileChangeSchema . parse ( parameters )
2020 const lines = fileChange . content . split ( '\n' )
2121
22- const { created, modified, invalid } = applyChanges ( cwd , [ fileChange ] )
22+ const { created, modified, invalid, patchFailed } = applyChanges ( cwd , [ fileChange ] )
2323
2424 const results : string [ ] = [ ]
2525
@@ -35,6 +35,12 @@ export function changeFile(
3535 )
3636 }
3737
38+ for ( const file of patchFailed ) {
39+ results . push (
40+ `Failed to write to ${ file } ; the patch failed to apply` ,
41+ )
42+ }
43+
3844 for ( const file of invalid ) {
3945 results . push (
4046 `Failed to write to ${ file } ; file path caused an error or file could not be written` ,
@@ -54,6 +60,7 @@ function applyChanges(
5460) {
5561 const created : string [ ] = [ ]
5662 const modified : string [ ] = [ ]
63+ const patchFailed : string [ ] = [ ]
5764 const invalid : string [ ] = [ ]
5865
5966 for ( const change of changes ) {
@@ -72,7 +79,8 @@ function applyChanges(
7279 const oldContent = fs . readFileSync ( fullPath , 'utf-8' )
7380 const newContent = applyPatch ( oldContent , content )
7481 if ( newContent === false ) {
75- throw new Error ( `Patch failed to apply to ${ filePath } : ${ content } ` )
82+ patchFailed . push ( filePath )
83+ continue
7684 }
7785 fs . writeFileSync ( fullPath , newContent )
7886 }
@@ -88,5 +96,5 @@ function applyChanges(
8896 }
8997 }
9098
91- return { created, modified, invalid }
99+ return { created, modified, invalid, patchFailed }
92100}
0 commit comments