mirror of
https://github.com/ZHANGTIANYAO1/teamspeak-music-bot.git
synced 2026-10-01 20:42:50 +08:00
fix(setup): stop a failed console write from aborting setup (#152)
setup.bat runs `chcp 65001` and shows binary progress on stderr. On some
Windows consoles - the reporter's Windows Server 2012 R2 above all - that
code page cannot render non-ASCII text and the OS fails the write with
EIO. process.stderr is an ordinary stream, so the EIO arrived as an
'error' event, and with no listener attached Node rethrew it as an
uncaught exception:
Error: write EIO { errno: -4070, code: 'EIO', syscall: 'write' }
at log (scripts/download-binaries.mjs:84:18)
at ensureFfmpeg (scripts/download-binaries.mjs:451:5)
Those two frames pin it exactly: line 84 is `process.stderr.write`, and
line 451 is the first log line of the whole run that contains Chinese.
The three lines before it are pure ASCII and printed fine. Nothing was
wrong with the download it was announcing - setup killed itself inside
its own progress logging and reported the native modules as unusable.
scripts/lib/console-log.mjs now wraps both streams: it listens for
'error' so the failure can never be fatal, then degrades that stream
rather than dying - first to an ASCII rendering that keeps the English
half of each bilingual line, then silent if the stream is really gone.
The streams degrade independently, so a console that gives up costs
setup.log nothing: that stdout is a redirected file. check-native.mjs
gets the same treatment, since the console that cannot print its Chinese
is exactly the one a user needs its English from.
Also report a 404 honestly. better-sqlite3 dropped its Node 20 (ABI 115)
prebuilds in 12.10.0 and @discordjs/opus 0.10.0 has none for Node 24, so
users on those majors fall through to the source build and are told to
install Python and a C++ toolchain - when switching Node major takes two
minutes. Nothing in the output said so, and the README recommended
Node 20 as if it still worked.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
af1dac848d
commit
5e9ae49f52
5 files changed
+321
-8
No files matched your search
@@ -51,6 +51,7 @@ import { Readable } from "node:stream";
|
||||
import { execFileSync, execSync } from "node:child_process";
|
||||
import { createRequire } from "node:module";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { createLineWriter } from "./lib/console-log.mjs";
|
||||
|
||||
const ROOT = join(dirname(fileURLToPath(import.meta.url)), "..");
|
||||
const NODE_MODULES = join(ROOT, "node_modules");
|
||||
@@ -61,6 +62,11 @@ const CDN = process.argv[2] || "https://cdn.npmmirror.com/binaries";
|
||||
const PLATFORM = process.platform;
|
||||
const ARCH = process.arch;
|
||||
const NODE_ABI = process.versions.modules;
|
||||
const NODE_MAJOR = Number(process.versions.node.split(".")[0]);
|
||||
/** The newest Node major this project is regularly tested against, and the one
|
||||
* every required addon currently ships a prebuild for. Keep in sync with
|
||||
* TESTED_NODE_MAJOR in scripts/setup.bat. */
|
||||
const TESTED_NODE_MAJOR = 22;
|
||||
|
||||
/** Modules the bot cannot start without. ffmpeg-static is optional: a system
|
||||
* ffmpeg on PATH is a documented fallback, so it only ever produces a WARN. */
|
||||
@@ -79,10 +85,17 @@ const FFMPEG_MIN_BYTES = 20 * 1024 * 1024;
|
||||
// log keeps the full transcript too.
|
||||
const ECHO_STDOUT = process.env.TSMB_BINARY_LOG_STDOUT === "1";
|
||||
|
||||
// Both writers swallow a failed write instead of letting it become an uncaught
|
||||
// 'error' event: a console that cannot print the Chinese half of a line (issue
|
||||
// #152) must not be able to abort a whole setup run. The two streams degrade
|
||||
// independently, so setup.log keeps the full bilingual transcript either way.
|
||||
const writeErr = createLineWriter(process.stderr);
|
||||
const writeOut = createLineWriter(process.stdout);
|
||||
|
||||
function log(msg) {
|
||||
const line = msg === "" ? "" : ` [binary] ${msg}`;
|
||||
process.stderr.write(`${line}\n`);
|
||||
if (ECHO_STDOUT) process.stdout.write(`${line}\n`);
|
||||
writeErr(line);
|
||||
if (ECHO_STDOUT) writeOut(line);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -401,6 +414,24 @@ function buildFromSource(command) {
|
||||
execSync(command, { cwd: ROOT, stdio: ["ignore", "inherit", "inherit"] });
|
||||
}
|
||||
|
||||
/**
|
||||
* A 404 from the CDN is not a mirror outage: it means this exact package
|
||||
* version publishes no prebuilt binary for the running Node ABI at all.
|
||||
* better-sqlite3 dropped its Node 20 (ABI 115) builds in 12.10.0, and
|
||||
* @discordjs/opus 0.10.0 has none for Node 24 (ABI 137) - so a user on either
|
||||
* of those majors lands in the source-build fallback below and is told to
|
||||
* install Python and a C++ toolchain. Switching Node major is the far cheaper
|
||||
* fix, and nothing else in this output points at it. See issue #152.
|
||||
*/
|
||||
function explainMissingPrebuild(name, version, err) {
|
||||
if (!/HTTP 404/.test(err.message)) return;
|
||||
log(`${name}: ${name}@${version} ships no prebuilt binary for Node ${NODE_MAJOR} (ABI ${NODE_ABI})`);
|
||||
log(
|
||||
`${name}: Node ${TESTED_NODE_MAJOR} LTS has one — switching Node is usually much quicker than ` +
|
||||
`setting up a compiler (换用 Node ${TESTED_NODE_MAJOR} LTS 通常比装编译环境快得多)`,
|
||||
);
|
||||
}
|
||||
|
||||
function buildToolsHint() {
|
||||
log("Install build tools first:");
|
||||
log(" Windows: npm install --global windows-build-tools (或安装 Visual Studio Build Tools + Python)");
|
||||
@@ -521,6 +552,7 @@ async function ensureOpus() {
|
||||
log(`${name}: prebuilt binary installed`);
|
||||
} catch (cdnErr) {
|
||||
log(`${name}: CDN install failed (${cdnErr.message})`);
|
||||
explainMissingPrebuild(name, version, cdnErr);
|
||||
log(`${name}: falling back to a source build — 'npm rebuild ${name}' (可能需要几分钟)`);
|
||||
buildFromSource(`npm rebuild ${name}`);
|
||||
}
|
||||
@@ -591,6 +623,7 @@ async function ensureBetterSqlite3() {
|
||||
log(`${name}: prebuilt binary installed (${humanSize(dest)})`);
|
||||
} catch (cdnErr) {
|
||||
log(`${name}: CDN install failed (${cdnErr.message})`);
|
||||
explainMissingPrebuild(name, version, cdnErr);
|
||||
log(`${name}: falling back to a source build — 'npm rebuild ${name} --build-from-source' (可能需要几分钟)`);
|
||||
buildFromSource(`npm rebuild ${name} --build-from-source`);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user