refactor: replace manual multi-level type guards with toRecord/isString in index.ts (#2731)

Two instances of the pattern `err && typeof err === "object" && "code" in err`
violated the type-safety rule requiring valibot or shared type-guard utilities
instead of manual multi-level type checks. Replaced with `toRecord(err)` and
`isString()` from @openrouter/spawn-shared for consistent, rule-compliant error
code extraction. Also bumps CLI patch version per cli-version.md.

-- qa/code-quality

Co-authored-by: spawn-qa-bot <qa@openrouter.ai>
Co-authored-by: L <6723574+louisgv@users.noreply.github.com>
This commit is contained in:
A 2026-03-17 18:40:16 -07:00 committed by GitHub
parent 234dd5e6e1
commit b1de116690
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 4 deletions

View file

@ -1,6 +1,6 @@
{
"name": "@openrouter/spawn",
"version": "0.21.0",
"version": "0.21.1",
"type": "module",
"bin": {
"spawn": "cli.js"

View file

@ -1,6 +1,6 @@
#!/usr/bin/env bun
import { getErrorMessage } from "@openrouter/spawn-shared";
import { getErrorMessage, isString, toRecord } from "@openrouter/spawn-shared";
import pc from "picocolors";
import pkg from "../package.json" with { type: "json" };
import {
@ -320,7 +320,8 @@ async function suggestCloudsForPrompt(agent: string): Promise<void> {
/** Print a descriptive error for a failed prompt file read and exit */
function handlePromptFileError(promptFile: string, err: unknown): never {
const code = err && typeof err === "object" && "code" in err ? err.code : "";
const errObj = toRecord(err);
const code = isString(errObj?.code) ? errObj.code : "";
if (code === "ENOENT") {
console.error(pc.red(`Prompt file not found: ${pc.bold(promptFile)}`));
console.error("\nCheck the path and try again.");
@ -353,7 +354,8 @@ async function readPromptFile(promptFile: string): Promise<string> {
});
if (!statsResult.ok) {
const err = statsResult.error;
const code = err && typeof err === "object" && "code" in err ? err.code : "";
const errRec = toRecord(err);
const code = isString(errRec?.code) ? errRec.code : "";
if (code === "ENOENT" || code === "EACCES" || code === "EISDIR") {
handlePromptFileError(promptFile, err);
}