@@ -378,6 +378,16 @@ function grokHomePath(env = process.env) {
378378 return env.GROK_HOME ? path.resolve(env.GROK_HOME) : path.join(os.homedir(), '.grok')
379379}
380380
381+ function isGrokCliUnavailableResult(result) {
382+ if (result?.error?.code === 'ENOENT' || result?.error?.code === 'EACCES') return true
383+ return Boolean(result && result.status === null && !result.signal && !result.stdout && !result.stderr)
384+ }
385+
386+ function formatGrokCommandOutput(result) {
387+ const output = String(result?.stderr || result?.stdout || '').trim()
388+ return output || result?.error?.message || 'no output'
389+ }
390+
381391function readInstalledPluginRegistry(env = process.env) {
382392 const registryFile = path.join(grokHomePath(env), 'installed-plugins', 'registry.json')
383393 if (!fs.existsSync(registryFile)) return { registryFile, value: { version: 1, repos: {} } }
@@ -429,7 +439,7 @@ function inspectGrokPluginInstallation(pluginPath, env = process.env) {
429439function syncGrokPluginInstallation({ pluginPath, dryRun = false, env = process.env }) {
430440 const source = path.resolve(pluginPath)
431441 const probe = spawnSync('grok', ['version'], { encoding: 'utf8', windowsHide: true, env })
432- if (probe.error?.code === 'ENOENT' ) {
442+ if (isGrokCliUnavailableResult( probe) ) {
433443 return {
434444 schemaVersion: 'GrokPluginInstallationReceiptV1',
435445 status: 'unavailable',
@@ -439,7 +449,7 @@ function syncGrokPluginInstallation({ pluginPath, dryRun = false, env = process.
439449 }
440450 }
441451 if (probe.status !== 0) {
442- const error = new Error(`GROK_PLUGIN_CLI_UNAVAILABLE: ${String (probe.stderr || probe.stdout).trim( )}`)
452+ const error = new Error(`GROK_PLUGIN_CLI_UNAVAILABLE: ${formatGrokCommandOutput (probe)}`)
443453 error.code = 'GROK_PLUGIN_CLI_UNAVAILABLE'
444454 throw error
445455 }
@@ -584,7 +594,7 @@ function syncGrokWorkspacePluginInstallation({
584594 }
585595
586596 const probe = spawnSync('grok', ['version'], { encoding: 'utf8', windowsHide: true, env })
587- if (probe.error?.code === 'ENOENT' ) {
597+ if (isGrokCliUnavailableResult( probe) ) {
588598 const configBase = configSnapshot.existed
589599 ? configSnapshot.content
590600 : (fs.existsSync(configPath) ? fs.readFileSync(configPath, 'utf8') : '')
@@ -614,7 +624,7 @@ function syncGrokWorkspacePluginInstallation({
614624 }
615625 }
616626 if (probe.status !== 0) {
617- const error = new Error(`GROK_PLUGIN_CLI_UNAVAILABLE: ${String (probe.stderr || probe.stdout).trim( )}`)
627+ const error = new Error(`GROK_PLUGIN_CLI_UNAVAILABLE: ${formatGrokCommandOutput (probe)}`)
618628 error.code = 'GROK_PLUGIN_CLI_UNAVAILABLE'
619629 throw error
620630 }
0 commit comments