lsongdev / lsongdev/node-escpos
[BUG]:network.open wrong error argument on callback in connect using bun
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 1.6k
- Forks
- 443
- PR merge metrics
- No merged PRs in 30d
Description
### Description of the bug
Using bun, escpos-network behaves differently in the open method, specifically the error argument.
It is set to a Socket instance when using bun (1.1.45+196621f25), not using node (22.8.0)
I also opened a [bug in bun](https://github.com/oven-sh/bun/issues/16564).
### Steps To Reproduce
I extracted the relevant code here and call both open (with a fix attempt) and open2 (current implementation in main). open2 fail with bun.
```javascript
const net = require('net');
const EventEmitter = require('events');
const util = require('util');
function Network(address, port) {
EventEmitter.call(this);
this.address = address;
this.port = port || 9100;
this.device = new net.Socket();
return this;
}
util.inherits(Network, EventEmitter);
Network.prototype.open = function(callback) {
const self = this;
this.device.on('error', (err) => {
console.log('error', err);
callback && callback(err, self.device);
}).on('data', buf => {
// console.log('printer say:', buf);
}).connect(this.port, this.address, function(err) {
if (err && err instanceof Error) {
console.log('connect error', err);
callback && callback(err, self.device);
return;
}
self.emit('connect', self.device);
callback && callback(null, self.device);
});
return this;
};
Network.prototype.open2 = function(callback){
var self = this;
this.device.on("error", (err) => {
callback && callback(err, self.device);
}).on('data', buf => {
// console.log('printer say:', buf);
}).connect(this.port, this.address, function(err){
self.emit('connect', self.device);
callback && callback(err, self.device);
});
return this;
};
// Usage example
let device = new Network('192.168.1.100', 9100);
device.open(function(error, device) {
if (error) {
console.log('Connection error open');
return;
}
console.log('Connected to device open');
device.end();
});
device = new Network('192.168.1.100', 9100);
device.open2(function(error, device) {
if (error) {
console.log('Connection error open2:');
return;
}
console.log('Connected to device open2');
device.end();
});
```
### Additional Information
_No response_
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating Network.prototype.open and comparing its callback handling under Node.js and Bun against the reproduction included in the issue. Done means the callback receives a consistent error value during connection failure in both runtimes; rerun the shown example to verify the behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- bun, javascript, node.js
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100