serverless-image-handler icon indicating copy to clipboard operation
serverless-image-handler copied to clipboard

Error when image is svg lambda return TypeError: Cannot read properties of undefined (reading 'toFormat')

Open chojs23 opened this issue 4 months ago • 2 comments

Describe the bug I'm using Dynamic Image Transformation for Amazon CloudFront. Version v7.0.6 with s3 object lambda and auto webp enabled. When attempt to get svg image from cloudfront I'm getting 500 error "Internal error. Please contact the system administrator.".

Here is my decoded request payload

{"bucket":"my-bucket","key":"attachments/bd3bd61f-1ffd-4738-9fdd-1fce6bb9337e","headers":{"Cache-Control":"max-age=31536000,public"}}

Here is full lambda error log

ERROR	TypeError: Cannot read properties of undefined (reading 'toFormat')
    at _ImageRequest.setup (/var/task/index.js:46047:96)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async handleRequest (/var/task/index.js:47165:30)
    at async Runtime.handler (/var/task/index.js:47132:25)

I also logged the imageRequestInfo.

INFO	{
  secondsToExpiry: undefined,
  requestType: 'Default',
  bucket: 'my-bucket',
  key: 'attachments/bd3bd61f-1ffd-4738-9fdd-1fce6bb9337e',
  edits: undefined,
  contentType: 'image/svg+xml',
  lastModified: 'Tue, 08 Jul 2025 06:28:03 GMT',
  cacheControl: 'max-age=31536000,public',
  originalImage: <Buffer 3c 3f 78 6d 6c 20 76 65 72 73 69 6f 6e 3d 22 31 2e 30 22 20 65 6e 63 6f 64 69 6e 67 3d 22 55 54 46 2d 38 22 3f 3e 0a 3c 73 76 67 20 69 64 3d 22 5f eb ... 3596 more bytes>
}

Looks like if there is no edits field in request, accessing imageRequestInfo.edits.toFormat without first checking if imageRequestInfo.edits exists throws error

Maybe same issue with #364

chojs23 avatar Aug 20 '25 01:08 chojs23

Hi, Thank you for raising this issue. We will look into this and get back to you.

bios6 avatar Aug 20 '25 13:08 bios6

thanks @chojs23, will replicate this at our end. what you mentioned seems to be the root cause, but we can replicate and confirm.

gsingh04 avatar Oct 29 '25 13:10 gsingh04