Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

[BUG]:network.open wrong error argument on callback in connect using bun

Aperta
#439 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
42/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
bun, javascript, node.js
Ambito
networking

Direzione di ricerca

Inizia individuando Network.prototype.open e confrontando la gestione del relativo callback in Node.js e Bun con la riproduzione inclusa nell’issue. Il lavoro è completato quando il callback riceve un valore di errore coerente durante un errore di connessione in entrambi i runtime; esegui nuovamente l’esempio mostrato per verificare il comportamento.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug
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.

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.

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

Lingua principale
TypeScript
Stelle
1.6k
Fork
443
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di lsongdev/node-escpos

Tutte le issue di lsongdev/node-escpos

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.