Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

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

オープン
#439 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
42/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
bun, javascript, node.js
領域
networking

調査の方向性

まず Network.prototype.open を見つけ、Node.js と Bun におけるその callback の処理を、issue に含まれている再現例と比較します。両方の runtime で接続に失敗した際に callback が一貫したエラー値を受け取れば完了です。動作を確認するため、示されている例を再実行してください。

索引モデルが issue の本文から書いたものです。

説明

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

主要言語
TypeScript
スター
1.6k
フォーク
443
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

lsongdev/node-escpos のほかの issue

lsongdev/node-escpos の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。