Skip to content

[Issue]: Standardize error output in linting scripts (Write-Host vs Write-Error) #371

@WilliamBerryiii

Description

@WilliamBerryiii

Issue Description

The linting scripts in scripts/linting/ use inconsistent error output methods. Most scripts use Write-Error for error reporting in catch blocks, but Invoke-YamlLint.ps1 uses Write-Host instead.

Current state in Invoke-YamlLint.ps1 (line 179):

catch {
    Write-Host "YAML Lint failed: $($_.Exception.Message)"
    if ($env:GITHUB_ACTIONS -eq 'true') {
        $escapedMsg = ConvertTo-GitHubActionsEscaped -Value $_.Exception.Message
        Write-Output "::error::$escapedMsg"
    }
    exit 1
}

Expected pattern (used by other scripts):

catch {
    Write-Error "YAML Lint failed: $($_.Exception.Message)"
    if ($env:GITHUB_ACTIONS -eq 'true') {
        $escapedMsg = ConvertTo-GitHubActionsEscaped -Value $_.Exception.Message
        Write-Output "::error::$escapedMsg"
    }
    exit 1
}

Recommendation

  1. File to modify: scripts/linting/Invoke-YamlLint.ps1

  2. Change required: Replace Write-Host with Write-Error at line 179

  3. Why this matters:

    • Write-Error writes to the error stream, which can be captured and redirected
    • Write-Host writes directly to the console and cannot be captured in $Error or redirected
    • Consistency across scripts makes the codebase easier to maintain
  4. Validation steps:

    npm run lint:ps    # Should pass PSScriptAnalyzer
    npm run test:ps    # Should pass all Pester tests
  5. Reference files showing the correct pattern:

    • scripts/linting/Invoke-PSScriptAnalyzer.ps1 (line ~153)
    • scripts/linting/Invoke-LinkLanguageCheck.ps1 (line ~127)
    • scripts/linting/Markdown-Link-Check.ps1 (line ~384)

Additional Context

This inconsistency was discovered during code review of PR #367. The fix is a single-line change and serves as a good introduction to the PowerShell linting infrastructure.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions