fix(installer): write error and help text to stderr for consistent stream output

Extracted help text into getHelpText() and write both the error message
and usage help to stderr via process.stderr.write(). This ensures that
when output is redirected (e.g. 2>errors.txt), both the error and the
guidance appear in the same stream.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Prabith Balagopalan
2026-03-26 18:18:45 +05:30
committed by Affaan Mustafa
parent d49c95a5ec
commit 24674a7bd6

View File

@@ -17,10 +17,10 @@ const {
parseInstallArgs, parseInstallArgs,
} = require('./lib/install/request'); } = require('./lib/install/request');
function showHelp(exitCode = 0) { function getHelpText() {
const languages = listLegacyCompatibilityLanguages(); const languages = listLegacyCompatibilityLanguages();
console.log(` return `
Usage: install.sh [--target <${LEGACY_INSTALL_TARGETS.join('|')}>] [--dry-run] [--json] <language> [<language> ...] Usage: install.sh [--target <${LEGACY_INSTALL_TARGETS.join('|')}>] [--dry-run] [--json] <language> [<language> ...]
install.sh [--target <${SUPPORTED_INSTALL_TARGETS.join('|')}>] [--dry-run] [--json] --profile <name> [--with <component>]... [--without <component>]... install.sh [--target <${SUPPORTED_INSTALL_TARGETS.join('|')}>] [--dry-run] [--json] --profile <name> [--with <component>]... [--without <component>]...
install.sh [--target <${SUPPORTED_INSTALL_TARGETS.join('|')}>] [--dry-run] [--json] --modules <id,id,...> [--with <component>]... [--without <component>]... install.sh [--target <${SUPPORTED_INSTALL_TARGETS.join('|')}>] [--dry-run] [--json] --modules <id,id,...> [--with <component>]... [--without <component>]...
@@ -44,8 +44,11 @@ Options:
Available languages: Available languages:
${languages.map(language => ` - ${language}`).join('\n')} ${languages.map(language => ` - ${language}`).join('\n')}
`); `;
}
function showHelp(exitCode = 0) {
console.log(getHelpText());
process.exit(exitCode); process.exit(exitCode);
} }
@@ -139,8 +142,8 @@ function main() {
printHumanPlan(result, false); printHumanPlan(result, false);
} }
} catch (error) { } catch (error) {
console.error(`Error: ${error.message}\n`); process.stderr.write(`Error: ${error.message}\n\n${getHelpText()}`);
showHelp(1); process.exit(1);
} }
} }