mirror of
https://github.com/OpenRouterTeam/spawn.git
synced 2026-05-22 03:14:57 +00:00
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:
parent
234dd5e6e1
commit
b1de116690
2 changed files with 6 additions and 4 deletions
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@openrouter/spawn",
|
||||
"version": "0.21.0",
|
||||
"version": "0.21.1",
|
||||
"type": "module",
|
||||
"bin": {
|
||||
"spawn": "cli.js"
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue