Working on a PowerShell module and noticed I'm having an issue when attempting to import it, no matter how
import-Module -Name ".\0.0.1\PSSymantecSEPM.psd1" -Force
An error occurred while running the REPL loop:
System.Management.Automation.ScriptCallDepthException: The script failed due to call depth overflow.
at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
at System.Management.Automation.PowerShell.Worker.ConstructPipelineAndDoWork(Runspace rs, Boolean performSyncInvoke)
at System.Management.Automation.PowerShell.Worker.CreateRunspaceIfNeededAndDoWork(Runspace rsToUse, Boolean isSync)
at System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
at System.Management.Automation.PowerShell.Invoke[T](IEnumerable input, PSInvocationSettings settings)
at Microsoft.PowerShell.EditorServices.Services.PowerShell.Utility.PowerShellExtensions.InvokeAndClear[TResult](PowerShell pwsh, PSInvocationSettings invocationSettings) in D:\a\_work\1\s\src\PowerShellEditorServices\Services\PowerShell\Utility\PowerShellExtensions.cs:line 76
After investigation, understood it's linked to recursion depth limit issue well described in a VSCode issue, but in my case it's not VSCode specific as I can reproduce without the integrated terminal
I assume now it's linked to my module directly, or manifest that somehow reaches this depth limit.
Anyone can point me to where/how I could fix this for this module ? Prepared some easy steps to reproduce via my personal project repo and specific branch I created to investigate this
# Closing repo
PS C:\Temp\test> git clone https://github.com/Douda/PSSymantecSEPM/
PS C:\Temp\test> cd .\PSSymantecSEPM\
# Switch to branch with issue
PS C:\Temp\test\PSSymantecSEPM> git checkout ScriptCallDepthException
Switched to a new branch 'ScriptCallDepthException'
branch 'ScriptCallDepthException' set up to track 'origin/ScriptCallDepthException'.
# attempting to import the module
PS C:\Temp\test\PSSymantecSEPM> Import-Module .\Output\PSSymantecSEPM\0.0.1\PSSymantecSEPM.psd1 -Force
The script failed due to call depth overflow.
+ CategoryInfo : InvalidOperation: (0:Int32) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : CallDepthOverflow
Tried with PS 5.1 & PS 7.4.0, same issue
$PSVersionTable
Name Value
---- -----
PSVersion 7.4.0
PSEdition Core
GitCommitId 7.4.0
OS Microsoft Windows 10.0.22631
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
I may also note, I am using ModuleBuilder to generate my module (and maintain versioning) but not sure it's linked
Thanks
.psm1to find which of the functions is using recursion and then understanding why said function is causing an infinite loop ?Initialize-SEPMConfigurationwill callReset-SEPMConfigurationwhich then callsInitialize-SEPMConfigurationwhich then callsReset-SEPMConfiguration... you get the point :) Remove that cyclic path and you should be goodInitialize-SepmConfigurationcallingReset-SEPMConfigurationwhich then is calling againInitialize-SepmConfigurationcausing an infinite loop.[Parser]::ParseFile(), then listed all statements at the root of the script - there was only one command invocation, so that narrowed it down pretty quickly