Skip to content

Enhancement: inject JS stack into errors originating from native code #3653

@mykola-mokhnach

Description

@mykola-mokhnach

Feature request

What are you trying to achieve?

The current error message thrown for unsupported/broken images (Error: Input buffer contains unsupported image format) would be more helpful if it had the list of supported image formats in it. Also, Node.js shows no stacktrace for such errors.

When you searched for similar feature requests, what did you find that might be related?

Simply init sharp with some random data:

import sharp from 'sharp';

const buf = Buffer.from('12345');
try {
  const img = sharp(buf);
} catch (err) {
  console.log(err.message);  // Input buffer contains unsupported image format
  console.log(err.stack); // Error: Input buffer contains unsupported image format
}

What would you expect the API to look like?

The error message could look like: Input buffer contains an unsupported image format. Only the following image formats are supported: PNG, JPEG, WEBP, so users could easily fix the input data themselves without checking additional documentation.
As far as I can see the exception itself is thrown inside of native code. Not sure if something special needs to be done for it, so a proper stacktrace is shown (btw I run Node.js 16@macOS 13.3.1).

What alternatives have you considered?

See above

Please provide sample image(s) that help explain this feature

See above

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions