Skip to content

Throw understandable error when empty file is passed #117

@DudaGod

Description

@DudaGod

Description

if one of the screenshots submitted for comparison is empty, an error is thrown:

RangeError [ERR_BUFFER_OUT_OF_BOUNDS]: Attempt to access memory outside buffer bounds

According to this error, the user does not understand what the problem is. So before reading the buffer, we need to check if it is empty. If it is empty, then we throw an understandable error. It would be even better to validate that the buffer is a png image.

Verify latest release

  • I verified that the issue exists in the latest looks-same release

Reproduction steps

  1. Create empty file - empty.png
  2. Run script:
const looksSame = require('looks-same');

(async () => {
    await looksSame('./empty.png', './empty.png');
})();

Actual Behavior

Get an incomprehensible error when starting the comparison of an empty image:

RangeError [ERR_BUFFER_OUT_OF_BOUNDS]: Attempt to access memory outside buffer bounds

Expected Behavior

Get an understandable error when starting the comparison of an empty image, for example:

File "empty.png" is not a valid png image

Which Node.js version are you using?

20.18.1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions