Skip to content

loadImage causes the process to terminate #2304

Closed

Description

Issue

A problem appeared in one of the projects, the process was silently terminating. In the end, the reason was determined - loadImage. A URL object was passed to the function as src instead of a string or buffer. But, what is strange is the process termination with no way to understand what is happening. Even the debugger (Node.js) could not help.

I think it would be more informative to throw an exception in canvas/lib/image.js when an invalid parameter is passed to setter. At the moment it is checking for a string or buffer and nothing else.

I was expecting an exception to be thrown that I could catch or at least a process crash with some information about the problem, but the process silently terminates. Is this a problem in bindings? Can someone explain the mechanism of this error? (I don't know C++ and bindings.)

Steps to Reproduce

const { loadImage } = require("canvas");
const { URL } = require("node:url");

async function main() {

  console.log("Start...");

  try {

    const userPhotoUrl = new URL("https://placehold.co/600x400");

    await loadImage(userPhotoUrl);

    console.log("Image loaded!");

  } catch (err) {

    console.error(err);

  }

  console.log("Done.");

}

main();

/*

Expected:
Start...
Image loaded!
Done.

Or:
Start...
<ERROR>
Done.

Result:
Start...

*/

Your Environment

OS: Ubuntu 22.04.3 LTS
Node.js: 16.16.0, 18.12.1, 18.16.1
node-canvas: 2.11.2, 2.10.0, 2.8.0, 2.6.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions