Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] install.ps1 fails via ssh/headless, windows server 2022, ansible #82

Open
jaw opened this issue Jan 3, 2024 · 3 comments
Open
Labels
bug Something isn't working

Comments

@jaw
Copy link

jaw commented Jan 3, 2024

Bug Report

Current Behavior

Install script fails due to color arguments in the script.

Error message:

{
  "changed": true,
  "debug": [],
  "error": [
    {
      "category_info": {
        "activity": "Write-InstallInfo",
        "category": "InvalidData",
        "category_id": 6,
        "reason": "ParentContainsErrorRecordException",
        "target_name": "",
        "target_type": ""
      },
      "error_details": null,
      "exception": {
        "help_link": null,
        "hresult": -2146233087,
        "inner_exception": null,
        "message": "Cannot process argument transformation on parameter 'ForegroundColor'. Cannot convert null to type \"System.ConsoleColor\" due to enumeration values that are not valid. Specify one of the following enumeration values and try again. The possible enumeration values are \"Black,DarkBlue,DarkGreen,DarkCyan,DarkRed,DarkMagenta,DarkYellow,Gray,DarkGray,Blue,Green,Cyan,Red,Magenta,Yellow,White\".",
        "source": null,
        "type": "System.Management.Automation.ParentContainsErrorRecordException"
      },
      "fully_qualified_error_id": "ParameterArgumentTransformationError,Write-InstallInfo",
      "output": "Write-InstallInfo : Cannot process argument transformation on parameter 'ForegroundColor'. Cannot convert null to type \r\n\"System.ConsoleColor\" due to enumeration values that are not valid. Specify one of the following enumeration values and \r\ntry again. The possible enumeration values are \"Black,DarkBlue,DarkGreen,DarkCyan,DarkRed,DarkMagenta,DarkYellow,Gray,Da\r\nrkGray,Blue,Green,Cyan,Red,Magenta,Yellow,White\".\r\nAt C:\\downloads\\scoop\\install.ps1:555 char:5\r\n+     Write-InstallInfo (\"Initializing...\")\r\n+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n    + CategoryInfo          : InvalidData: (:) [Write-InstallInfo], ParentContainsErrorRecordException\r\n    + FullyQualifiedErrorId : ParameterArgumentTransformationError,Write-InstallInfo\r\n \r\n",
      
      "pipeline_iteration_info": [],
      "script_stack_trace": "at Install-Scoop, C:\\downloads\\scoop\\install.ps1: line 555\r\nat <ScriptBlock>, C:\\downloads\\scoop\\install.ps1: line 694\r\nat <ScriptBlock>, <No file>: line 2",
      "target_object": null
    }
  ],
  "host_err": "",
  "host_out": "",
  "information": [],
  "output": [],
  "result": {},
  "verbose": [],
  "warning": []
}

Expected Behavior

Not to throw this exception.

Additional context/output

Possible Solution

I worked around this by removing the terminal color code in the Write-InstallInfo function of the install script.

System details

Windows version: Server 2022

OS architecture: 64bit

PowerShell version: 5.1

@jaw jaw added the bug Something isn't working label Jan 3, 2024
@r15ch13
Copy link
Member

r15ch13 commented Jan 6, 2024

It seems that $host.UI.RawUI.ForegroundColor returns null with this setup.

Install/install.ps1

Lines 72 to 89 in 656e17b

function Write-InstallInfo {
param(
[Parameter(Mandatory = $True, Position = 0)]
[String] $String,
[Parameter(Mandatory = $False, Position = 1)]
[System.ConsoleColor] $ForegroundColor = $host.UI.RawUI.ForegroundColor
)
$backup = $host.UI.RawUI.ForegroundColor
if ($ForegroundColor -ne $host.UI.RawUI.ForegroundColor) {
$host.UI.RawUI.ForegroundColor = $ForegroundColor
}
Write-Output "$String"
$host.UI.RawUI.ForegroundColor = $backup
}

Could you try this modified Write-InstallInfo function?

function Write-InstallInfo {
    param(
        [Parameter(Mandatory = $True, Position = 0)]
        [String] $String,
        [Parameter(Mandatory = $False, Position = 1)]
        [System.ConsoleColor] $ForegroundColor = 'Gray'
    )

    $backup = $host.UI.RawUI.ForegroundColor
    if ($null -eq $backup) {
        $backup = 'Gray'
    }
    if ($null -eq $ForegroundColor) {
        $ForegroundColor = 'Gray'
    }

    if ($ForegroundColor -ne $host.UI.RawUI.ForegroundColor) {
        $host.UI.RawUI.ForegroundColor = $ForegroundColor
    }

    Write-Output "$String"

    $host.UI.RawUI.ForegroundColor = $backup
}

@jaw
Copy link
Author

jaw commented Jan 15, 2024

Here is the result:

    {
      "category_info": {
        "activity": "Write-InstallInfo",
        "category": "NotSpecified",
        "category_id": 0,
        "reason": "SetValueInvocationException",
        "target_name": "",
        "target_type": ""
      },
      "error_details": null,
      "exception": {
        "help_link": null,
        "hresult": -2146233087,
        "inner_exception": {
          "help_link": null,
          "hresult": -2146233087,
          "inner_exception": null,
          "message": "A command that prompts the user failed because the host program or the command type does not support user interaction. Try a host program that supports user interaction, such as the Windows PowerShell Console or Windows PowerShell ISE, and remove prompt-related commands from command types that do not support user interaction, such as Windows PowerShell workflows.",
          "source": "System.Management.Automation",
          "type": "System.Management.Automation.Host.HostException"
        },
        "message": "Exception setting \"ForegroundColor\": \"A command that prompts the user failed because the host program or the command type does not support user interaction. Try a host program that supports user interaction, such as the Windows PowerShell Console or Windows PowerShell ISE, and remove prompt-related commands from command types that do not support user interaction, such as Windows PowerShell workflows.\"",
        "source": "System.Management.Automation",
        "type": "System.Management.Automation.SetValueInvocationException"
      },
      "fully_qualified_error_id": "ExceptionWhenSetting,Write-InstallInfo",
      "output": "Write-InstallInfo : Exception setting \"ForegroundColor\": \"A command that prompts the user failed because the host \r\nprogram or the command type does not support user interaction. Try a host program that supports user interaction, such \r\nas the Windows PowerShell Console or Windows PowerShell ISE, and remove prompt-related commands from command types that \r\ndo not support user interaction, such as Windows PowerShell workflows.\"\r\nAt C:\\downloads\\scoop\\scoop_install.ps1:561 char:5\r\n+     Write-InstallInfo \"Initializing...\"\r\n+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n    + CategoryInfo          : NotSpecified: (:) [Write-InstallInfo], SetValueInvocationException\r\n    + FullyQualifiedErrorId : ExceptionWhenSetting,Write-InstallInfo\r\n \r\n",
      "pipeline_iteration_info": [
        0,
        1
      ],
      "script_stack_trace": "at Write-InstallInfo, C:\\downloads\\scoop\\scoop_install.ps1: line 89\r\nat Install-Scoop, C:\\downloads\\scoop\\scoop_install.ps1: line 561\r\nat <ScriptBlock>, C:\\downloads\\scoop\\scoop_install.ps1: line 700\r\nat <ScriptBlock>, <No file>: line 2",
      "target_object": null
    }

@xPancakery
Copy link

I am also getting this error, to validate the other users bug report.

@rashil2000 rashil2000 transferred this issue from ScoopInstaller/Scoop Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants