fix: handle stockfish process error, try /usr/games/stockfish path
This commit is contained in:
@@ -30,10 +30,21 @@ export class StockfishEngine {
|
|||||||
|
|
||||||
private async init() {
|
private async init() {
|
||||||
try {
|
try {
|
||||||
this.process = spawn("stockfish", [], {
|
// Debian installs stockfish to /usr/games/stockfish
|
||||||
|
const sfBin = ["/usr/games/stockfish", "/usr/bin/stockfish", "stockfish"]
|
||||||
|
.find(p => { try { require("fs").accessSync(p); return true; } catch { return false; } })
|
||||||
|
?? "stockfish";
|
||||||
|
|
||||||
|
this.process = spawn(sfBin, [], {
|
||||||
stdio: ["pipe", "pipe", "pipe"],
|
stdio: ["pipe", "pipe", "pipe"],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.process.on("error", (err) => {
|
||||||
|
console.error("Stockfish process error:", err.message);
|
||||||
|
this.process = null;
|
||||||
|
this.ready = false;
|
||||||
|
});
|
||||||
|
|
||||||
await new Promise<void>((resolve) => {
|
await new Promise<void>((resolve) => {
|
||||||
let readyOk = false;
|
let readyOk = false;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user