{"record":{"id":"07dcc245fb52aa47","repo":"pydantic/monty","slug":"monty-binary-not-found-at-binarypath-explicit","errorCode":null,"errorMessage":"monty binary not found at binaryPath: ${explicit}","messagePattern":"monty binary not found at binaryPath: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"crates/monty-js/ts/binary.ts","lineNumber":43,"sourceCode":"    return `darwin-${arch}`\n  }\n  if (platform === 'linux' && (arch === 'x64' || arch === 'arm64')) {\n    return `linux-${arch}-gnu`\n  }\n  if (platform === 'win32' && arch === 'x64') {\n    return 'win32-x64-msvc'\n  }\n  return null\n}\n\n/**\n * Resolves the `monty` binary path, throwing a descriptive error naming\n * every location tried when nothing is found.\n */\nexport function findMontyBinary(explicit?: string): string {\n  if (explicit !== undefined) {\n    if (!existsSync(explicit)) {\n      throw new Error(`monty binary not found at binaryPath: ${explicit}`)\n    }\n    return explicit\n  }\n\n  const tried: string[] = []\n\n  const envBin = process.env.MONTY_BIN\n  if (envBin) {\n    if (existsSync(envBin)) {\n      return envBin\n    }\n    tried.push(`MONTY_BIN=${envBin}`)\n  }\n\n  const fromPackage = platformPackageBinary()\n  if (fromPackage !== null) {\n    return fromPackage\n  }","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/pydantic/monty/blob/adc986b362e3961f407868cb118a99fe831b9e61/crates/monty-js/ts/binary.ts#L25-L61","documentation":"Thrown by `findMontyBinary` when an explicit `binaryPath` was supplied but no file exists at that path. The library trusts an explicit path as authoritative — it does not fall back to MONTY_BIN, the platform package, PATH, or the cargo workspace — so a wrong path fails fast with a message naming the exact path. This lets you distinguish 'you gave me a bad path' from 'I could not find any binary'.","triggerScenarios":"Calling `Monty.create({ binaryPath: ... })` (or any API that resolves the binary via `findMontyBinary(explicit)`) with a path that does not exist: a typo, a deleted binary after `cargo clean`, a relative path resolved from a different working directory, a path valid on a dev machine but not in CI/production.","commonSituations":"Hard-coding `target/debug/monty` from another checkout; Docker images built without copying the binary; switching from a local dev build to a production image where the workspace build is absent; platform suffix mistakes on Windows (`monty` instead of `monty.exe`).","solutions":["Verify the path exists at runtime: `existsSync(binaryPath)` before constructing the pool","Use an absolute path (`path.resolve(...)`) so it does not depend on the process cwd","On Windows point at the `.exe` (`monty.exe`), on other platforms at `monty`","If the path is optional, pass `undefined` instead of a bogus value so resolution falls through to MONTY_BIN / the platform package"],"exampleFix":"// before\nconst pool = await Monty.create({ binaryPath: './monty' }) // relative, may not exist\n// after\nimport { existsSync } from 'node:fs'\nconst bin = path.resolve(process.env.MONTY_BIN ?? './target/debug/monty')\nif (!existsSync(bin)) throw new Error(`monty binary missing at ${bin}`)\nconst pool = await Monty.create({ binaryPath: bin })","handlingStrategy":"validation","validationCode":"import { existsSync, statSync } from 'node:fs'\nfunction validateBinaryPath(p: string): string {\n  if (!existsSync(p)) throw new Error(`monty binary missing at '${p}'`)\n  if (!statSync(p).isFile()) throw new Error(`'${p}' is not a file`)\n  return p\n}\nconst pool = await Monty.create({ binaryPath: validateBinaryPath(myPath) })","typeGuard":"const isExistingFile = (p: string): boolean => { try { return statSync(p).isFile() } catch { return false } }","tryCatchPattern":"try {\n  const pool = await Monty.create({ binaryPath: explicit })\n} catch (err) {\n  if ((err as Error).message.startsWith('monty binary not found at binaryPath')) {\n    // fall back to auto-resolution: omit binaryPath entirely\n    return Monty.create()\n  }\n  throw err\n}","preventionTips":["Resolve with `path.resolve()` so the path is absolute and cwd-independent","Check `existsSync` at startup, before creating the pool","Never hard-code dev-machine paths; derive from env or config with validation","Remember `monty.exe` on Windows vs `monty` elsewhere"],"tags":["nodejs","filesystem","configuration"],"backgroundTag":"file-not-found","analyzedSha":"adc986b362e3961f407868cb118a99fe831b9e61","analyzedAt":"2026-09-13T19:19:18.698Z","contentChangedAt":"2026-09-13T19:19:18.698Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}