hMatoba / piexifjs

Read and modify exif in client-side or server-side JavaScript.
MIT License
572 stars 119 forks source link

'pack' error. Got invalid type argument #43

Closed micahjon closed 6 years ago

micahjon commented 6 years ago

Hi, we're using Piexifjs in production at BeFunky (an online photo editor) and have been getting this error pretty often: 'pack' error. Got invalid type argument

I looked over the call sites of the pack() function, and my best guess is that the culprit is line 457, where _dict_to_bytes() converts raw_value to an array if its a number, but not if its any other type (string, undefined, null, etc).

I'll let you know if I'm able to get an actual stack trace, but I just wanted to pass this along in case it was an oversight. Thanks for this super handy library.

tomscript commented 6 years ago

Seeing this by way of https://www.npmjs.com/package/jpeg-autorotate. Friendly ping

hMatoba commented 6 years ago

Thank you for letting me know. In version 2.0, I add some type checks. It's will resolve this issue. https://github.com/hMatoba/piexifjs/blob/2.0/src/utils.ts#L486

Could you re-open this issue, when you get the image that throw this error?

micahjon commented 5 years ago

@hMatoba , glad to hear you're working on a 2.0.

In the meantime, I discovered that the reason there's no stack trace is that you're throwing a string instead of an Error object, e.g.

Missing stack trace:

throw "'pack' error"

Has stack trace:

throw new Error("'pack' error")

If you'd like, I can submit a PR. Just let me know

hMatoba commented 5 years ago

Could you send me PR?

micahjon commented 5 years ago

Sure, just submitted one.