@trim21/personal-pi-extensions 0.0.239 → 0.0.240
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/gh-readonly.ts +29 -5
package/package.json
CHANGED
package/src/gh-readonly.ts
CHANGED
|
@@ -46,6 +46,8 @@ interface GhResult {
|
|
|
46
46
|
combined: string;
|
|
47
47
|
/** Why the process was killed, when `killed` is true. */
|
|
48
48
|
reason?: "timeout" | "abort";
|
|
49
|
+
/** When the process could not be started at all (e.g. `gh` not found in PATH). */
|
|
50
|
+
spawnError?: string;
|
|
49
51
|
}
|
|
50
52
|
|
|
51
53
|
// ── helpers ──────────────────────────────────────────────────────────────────
|
|
@@ -131,12 +133,22 @@ export function runGh(
|
|
|
131
133
|
});
|
|
132
134
|
});
|
|
133
135
|
|
|
134
|
-
proc.on("error", () => {
|
|
136
|
+
proc.on("error", (err: Error) => {
|
|
135
137
|
if (timeoutId) clearTimeout(timeoutId);
|
|
136
138
|
if (onAbort && ctx.signal) {
|
|
137
139
|
ctx.signal.removeEventListener("abort", onAbort);
|
|
138
140
|
}
|
|
139
|
-
|
|
141
|
+
// spawn 失败(如 gh 不在 PATH → ENOENT、cwd 不存在)时进程从未启动,
|
|
142
|
+
// 没有任何 stdout/stderr;把底层错误带上,否则会退化成无信息的 "exit code 1"。
|
|
143
|
+
resolve({
|
|
144
|
+
stdout,
|
|
145
|
+
stderr,
|
|
146
|
+
code: 1,
|
|
147
|
+
killed,
|
|
148
|
+
combined: combined.join(""),
|
|
149
|
+
reason: killReason,
|
|
150
|
+
spawnError: err.message,
|
|
151
|
+
});
|
|
140
152
|
});
|
|
141
153
|
});
|
|
142
154
|
}
|
|
@@ -162,9 +174,21 @@ export class GhError extends Error {
|
|
|
162
174
|
? " (command aborted)"
|
|
163
175
|
: ""
|
|
164
176
|
: "";
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
177
|
+
|
|
178
|
+
// The process never started (e.g. `gh` not found): surface the spawn error.
|
|
179
|
+
// Otherwise show the command's own output; an empty output with a non-zero
|
|
180
|
+
// exit is explicitly marked, so a bare "exit code 1" can't be mistaken for
|
|
181
|
+
// a specific failure.
|
|
182
|
+
let outputText: string;
|
|
183
|
+
if (result.spawnError) {
|
|
184
|
+
outputText = `spawn failed: ${result.spawnError}`;
|
|
185
|
+
} else if (result.combined.trim()) {
|
|
186
|
+
outputText = result.combined.trim();
|
|
187
|
+
} else {
|
|
188
|
+
outputText = `exit code ${result.code} (no output)`;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
super(`${inputText}<output>${outputText}${killedText}<output>`);
|
|
168
192
|
this.name = "GhError";
|
|
169
193
|
this.args = args;
|
|
170
194
|
this.code = result.code;
|