gemini-testing / gemini-testing/looks-same
Throw understandable error when empty file is passed
- Dominant language
- JavaScript
- Stars
- 827
- Forks
- 55
- PR merge metrics
- No merged PRs in 30d
Description
### 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
- [x] I verified that the issue exists in the latest looks-same release
### Reproduction steps
1. Create empty file - `empty.png`
2. Run script:
```javascript
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
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.