jimp-dev / jimp

An image processing library written entirely in JavaScript for Node, with zero external or native dependencies.
http://jimp-dev.github.io/jimp/
MIT License
14.04k stars 760 forks source link

`getBufferAsync()` throws a string instead of an Error #1057

Closed nopeless closed 1 year ago

nopeless commented 2 years ago

Expected Behavior

    Jimp.read(v)
      .then(lenna => lenna.resize(2000, Jimp.AUTO).getBufferAsync(`png`))
      .catch(e => {
        console.log(`type of e`, typeof e);
        throw e;
      })

Should log object

Current Behavior

logs string

Failure Information (for bugs)

Steps to Reproduce

Here is a minimal reproducible example

import Jimp from "jimp";

Jimp.read(`response.png`)
  .then(lenna => lenna.resize(2000, Jimp.AUTO).getBufferAsync(`png`))
  .catch(e => {
    console.log(`type of e should be object`, typeof e);
    console.log(`e should be an instance of Error`, e instanceof Error);
  });

Context

I am reporting this error because this broke my error catching express middleware.

image

Before the fix

Fixing by doing

      .catch(e => {
        console.log(`type of e`, typeof e);
        throw new Error(e);
      })

After the fix

image

Hope to see this fixed soon 👍

nopeless commented 2 years ago

bump

intradeus commented 2 years ago

'png' written like this isn't a MIME type ! Replace .getBufferAsync(`png`) with .getBufferAsync(Jimp.MIME_PNG) instead

nopeless commented 2 years ago

@intradeus @noahdeering can you please read. the issue states that the function is throwing a string not an error

nopeless commented 1 year ago

bump

hipstersmoothie commented 1 year ago

If anyone wants to submit a PR for this issue the fix should be easy. Willing to help merge and release!

nopeless commented 1 year ago

@hipstersmoothie #1138