kpdecker / jsdiff

A javascript text differencing implementation.
BSD 3-Clause "New" or "Revised" License
7.75k stars 491 forks source link

createPatch & createTwoFilesPatch throw meaningless exceptions if structuredPatch returns undefined #463

Closed ExplodingCabbage closed 6 months ago

ExplodingCabbage commented 6 months ago

Example:

> diff.createPatch("file1", "foo\nbar\n", "foodie\nbarbell", undefined, undefined, {maxEditLength: 1})
Uncaught TypeError: Cannot read properties of undefined (reading 'oldFileName')
    at formatPatch (/home/mark/jsdiff/lib/patch/create.js:241:12)
    at createTwoFilesPatch (/home/mark/jsdiff/lib/patch/create.js:270:10)
    at Object.createPatch (/home/mark/jsdiff/lib/patch/create.js:274:10)

We should propagate the failure that structuredPatch has signalled to us (by way of returning undefined) in a more useful way.

ExplodingCabbage commented 6 months ago

(Remember to update the README when fixing this!)