Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail more gracefully if EXIF date is missing #15

Closed
KasparEtter opened this issue Mar 12, 2020 · 1 comment
Closed

Fail more gracefully if EXIF date is missing #15

KasparEtter opened this issue Mar 12, 2020 · 1 comment

Comments

@KasparEtter
Copy link
Contributor

rename picture-without-exif.jpg '{{exif|date}} {{f}}'

results in

/usr/local/lib/node_modules/rename-cli/lib/replacements.js:419
          let formattedDate = data.DateTime.split(/:|\s/)[1] + '/' + data.DateTime.split(/:|\s/)[2] + '/' + data.DateTime.split(/:|\s/)[0] + ' ' + data.DateTime.split(/:|\s/)[3] + ':' + data.DateTime.split(/:|\s/)[4] + ':' + data.DateTime.split(/:|\s/)[5];
                                            ^

TypeError: Cannot read property 'split' of undefined
    at Object.function (/usr/local/lib/node_modules/rename-cli/lib/replacements.js:419:45)
    at replaceVariables (/usr/local/lib/node_modules/rename-cli/rename.js:289:89)
    at /usr/local/lib/node_modules/rename-cli/rename.js:50:29
    at Array.forEach (<anonymous>)
    at Object.getOperations (/usr/local/lib/node_modules/rename-cli/rename.js:33:9)
    at renameFiles (/usr/local/lib/node_modules/rename-cli/bin.js:79:27)
    at parseArgs (/usr/local/lib/node_modules/rename-cli/bin.js:66:5)
    at /usr/local/lib/node_modules/rename-cli/bin.js:50:7
    at /usr/local/lib/node_modules/rename-cli/node_modules/graceful-fs/graceful-fs.js:115:16
    at FSReqCallback.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:63:3)

(Obviously, the above example is construed. I encountered the problem while renaming a bunch of files with rename * and now I have to sort out the pictures without EXIF manually.)

The problem is that the check on data.DateTime comes one line too late:

let formattedDate = data.DateTime.split(/:|\s/)[1] + '/' + data.DateTime.split(/:|\s/)[2] + '/' + data.DateTime.split(/:|\s/)[0] + ' ' + data.DateTime.split(/:|\s/)[3] + ':' + data.DateTime.split(/:|\s/)[4] + ':' + data.DateTime.split(/:|\s/)[5];
returnText = (typeof(data) === 'object' && data.DateTime ? dateFormat(formattedDate, dFormat) : '');

The existing intention seems to be to just return/use an empty string in such a case. I think it would also be desirable to get a warning on the console in such a case (and maybe skip renaming the file or use a string like ERROR or NOEXIF instead). I don't have a strong preference other than that code shouldn't crash and continue with the remaining files.

@jhotmann
Copy link
Owner

Fixed in 6.1.0

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

No branches or pull requests

2 participants