Pode icon indicating copy to clipboard operation
Pode copied to clipboard

Server will not start if failing to load modules

Open claw0ry opened this issue 3 years ago • 0 comments

Describe the Bug

I've been using oh-my-posh for a while and today I wanted to try out Pode. When I try to start the pode server (pode start) it will throw an exception because there is a module it cannot load.

In my case, I found out that this was caused by oh-my-posh dynamically creating a module called "oh-my-posh-core". The module is listed when running Get-Module, but the path reported does not exist and is a guid that is new for each session.

PS> (Get-Module -Name oh-my-posh-core).Path
/Users/aa/3360407f-4100-4347-986d-002902c38c87

This can be fixed by changing -ErrorAction Stop to -ErrorAction SilentlyContinue in src/Private/Helpers.ps1 on line 912.

Is there a reason you want to use -ErrorAction Stop when loading other modules in Pode?

Steps To Reproduce

Steps to reproduce the behavior:

  1. Use oh-my-posh to customize prompt in powershell
  2. Create a basic Pode server from docs (server.ps1)
  3. Run pode start

Expected Behavior

A clear and concise description of what you expected to happen.

Platform

  • OS: MacOS 12.6
  • Browser: N/A
  • Versions:
    • Pode: 2.7.1
    • PowerShell: PS7.2.6

Additional Context

Thrown error:

Import-Module: /Users/aa/.local/share/powershell/Modules/Pode/2.7.1/Private/Helpers.ps1:913
Line |
 913 |  …     $null = Import-Module $path -DisableNameChecking -Scope Global -E …
     |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | The specified module '/Users/aa/3360407f-4100-4347-986d-002902c38c87' was not loaded because no valid module file was found in any module directory.

at Import-PodeModules, /Users/aa/.local/share/powershell/Modules/Pode/2.7.1/Private/Helpers.ps1: line 913
at Open-PodeRunspace, /Users/aa/.local/share/powershell/Modules/Pode/2.7.1/Private/Helpers.ps1: line 603
at <ScriptBlock>, <No file>: line 1

Import-Module: /Users/aa/.local/share/powershell/Modules/Pode/2.7.1/Private/Helpers.ps1:913
Line |
 913 |  …     $null = Import-Module $path -DisableNameChecking -Scope Global -E …
     |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | The specified module '/Users/aa/3360407f-4100-4347-986d-002902c38c87' was not loaded because no valid module file was found in any module directory.

at Import-PodeModules, /Users/aa/.local/share/powershell/Modules/Pode/2.7.1/Private/Helpers.ps1: line 913
at Open-PodeRunspace, /Users/aa/.local/share/powershell/Modules/Pode/2.7.1/Private/Helpers.ps1: line 603
at <ScriptBlock>, <No file>: line 1
ParentContainsErrorRecordException: /Users/aa/.local/share/powershell/Modules/Pode/2.7.1/Private/Helpers.ps1:723
Line |
 723 |          throw $_.Exception
     |          ~~~~~~~~~~~~~~~~~~
     | Main runspace failed to load: The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: The specified module
     | '/Users/aa/3360407f-4100-4347-986d-002902c38c87' was not loaded because no valid module file was found in any module directory.

claw0ry avatar Sep 21 '22 07:09 claw0ry