oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.36k stars 2.78k forks source link

error: UV_ENOENT when using webtorrent #14234

Open kaiser101 opened 1 month ago

kaiser101 commented 1 month ago

What version of Bun is running?

1.1.29+6d43b3662

What platform is your computer?

Microsoft Windows NT 10.0.19045.0 x64

What steps can reproduce the bug?

index.js

import WebTorrent from 'webtorrent';

const client = new WebTorrent();
const magnet_url = '0D4AF725CC7CDF3CE933E5BFF8C0B3A6ED6E0D93';

const torrentOps = (magnetURI) => (torrent) => {
  torrent.on('download', downloadOp(torrent));

  torrent.on('done', doneOp(client, magnetURI, torrent));
};

client.add(
  magnet_url,
  {
    announce: [
      'udp://tracker.opentrackr.org:1337/announce',
      'http://tracker.opentrackr.org:1337/announce',
      'udp://open.demonii.com:1337/announce',
      'udp://open.stealth.si:80/announce',
      'udp://tracker.torrent.eu.org:451/announce',
      'udp://exodus.desync.com:6969/announce',
      'https://tracker.tamersunion.org:443/announce',
      'udp://tracker1.bt.moack.co.kr:80/announce',
    ],
    path: './torrents',
  },
  torrentOps(magnet_url)
);

const downloadOp = (torrent) => (bytes) => {
  const { downloaded, downloadSpeed, progress, timeRemaining, infoHash } =
    torrent;

  console.info(`downloadSpeed = ${downloadSpeed}`);
};

const doneOp = (client, magnetURI, torrent) => () => {
  console.info(`Torrent ${torrent.name} download finished`);

  client.remove(magnetURI, (err) => {
    console.warn(err ?? 'Torrent removed');
  });
};

package.json

{
  "name": "webtorrent_sample",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "description": "",
  "dependencies": {
    "webtorrent": "^2.5.1"
  },
  "type": "module",
  "trustedDependencies": [
    "node-datachannel"
  ]
}

What is the expected behavior?

Expected output is all torrent files are downloaded under the torrents folder. The same code works perfectly with node, without even having to add "trustedDependencies": ["node-datachannel"] in package.json

What do you see instead?

While running this with bun, the folders are created, but it gives an error while writing the files to disk.

error: UV_ENOENT
   errno: -4058
 syscall: "open"
   path: "C:\Temp\Npm projects\webtorrent_sample\torrents\Python Programming And Maching Learning Understanding How To Code Within 24 Hours 2 In 1\Please Consider Making A Donation\QR Code For Donations.jpg"

Additional information

No response

nektro commented 1 month ago
debug log on macos ``` ❯ ~/src/bun3/build/debug/bun-debug index.js ASSERTION FAILED: JS assertion failed at line 1 in: function (entry, fetcher) { // "use strict"; if (entry.evaluated) return; entry.evaluated = true; // var dependencies = entry.dependencies; if (!entry.isAsync) { // for (var i = 0, length = dependencies.length; i < length; ++i) { var dependency = dependencies[i]; @assert(!dependency.isAsync); this.moduleEvaluation(dependency, fetcher); } this.evaluate(entry.key, entry.module, fetcher); } else return this.asyncModuleEvaluation(entry, fetcher, dependencies); } false src/bun.js/WebKit/Source/JavaScriptCore/runtime/JSGlobalObject.cpp(432) : JSC::EncodedJSValue JSC::assertCall(JSGlobalObject *, CallFrame *) 1 0x105525878 JSC::assertCall(JSC::JSGlobalObject*, JSC::CallFrame*) 2 0x12080421c 1 ??? 0x000000012080421c 0x0 + 4840243740 3 0x120872f68 2 ??? 0x0000000120872f68 0x0 + 4840697704 4 0x10632ff84 llint_entry 5 0x120839b6c 4 ??? 0x0000000120839b6c 0x0 + 4840463212 6 0x10633151c llint_entry 7 0x10632ff84 llint_entry 8 0x120839b6c 7 ??? 0x0000000120839b6c 0x0 + 4840463212 9 0x120842028 8 ??? 0x0000000120842028 0x0 + 4840497192 10 0x1063087b4 vmEntryToJavaScript 11 0x1050ca2d8 JSC::Interpreter::executeCallImpl(JSC::VM&, JSC::JSObject*, JSC::CallData const&, JSC::JSValue, JSC::ArgList const&) 12 0x105575cec JSC::runJSMicrotask(JSC::JSGlobalObject*, WTF::ObjectIdentifierGeneric, unsigned long long, (WTF::SupportsObjectIdentifierNullState)1>, JSC::JSValue, JSC::JSValue, JSC::JSValue, JSC::JSValue, JSC::JSValue) 13 0x1057c9de8 JSC::VM::drainMicrotasks() 14 0x100385df8 Bun::jsFunctionDrainMicrotaskQueue(JSC::JSGlobalObject*, JSC::CallFrame*) 15 0x12080421c 14 ??? 0x000000012080421c 0x0 + 4840243740 16 0x12086a148 15 ??? 0x000000012086a148 0x0 + 4840661320 17 0x1063087b4 vmEntryToJavaScript 18 0x1050ca2d8 JSC::Interpreter::executeCallImpl(JSC::VM&, JSC::JSObject*, JSC::CallData const&, JSC::JSValue, JSC::ArgList const&) 19 0x10536c9e8 JSC::call(JSC::JSGlobalObject*, JSC::JSValue, JSC::JSValue, JSC::ArgList const&, WTF::ASCIILiteral) 20 0x1004d73e0 Bun::JSNextTickQueue::drain(JSC::VM&, JSC::JSGlobalObject*) 21 0x100639870 Zig::GlobalObject::drainMicrotasks() 22 0x1006398c8 JSC__JSGlobalObject__drainMicrotasks 23 0x101cc87ac src.bun.js.event_loop.EventLoop.drainMicrotasksWithGlobal 24 0x10233199c src.bun.js.event_loop.EventLoop.tickQueueWithCount__anon_142913 25 0x101cc8700 src.bun.js.event_loop.EventLoop.tickWithCount 26 0x10185f9e8 src.bun.js.event_loop.EventLoop.tick 27 0x1026af66c src.bun.js.event_loop.EventLoop.waitForPromise 28 0x101fb43e8 src.bun.js.javascript.VirtualMachine.waitForPromise 29 0x10217419c src.bun.js.javascript.VirtualMachine.loadEntryPoint 30 0x101b012cc src.bun_js.Run.start 31 0x10154c8a8 src.bun.js.javascript.OpaqueWrap__anon_58642__struct_93622.callback [1] 45275 trace trap ~/src/bun3/build/debug/bun-debug index.js ```