Dot Sourcing module functions seems to 'break' breakpoints

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
User avatar
HONDAAL
Posts: 10
Joined: Thu May 06, 2010 7:56 am

Dot Sourcing module functions seems to 'break' breakpoints

Post by HONDAAL »

Product, version and build: PowerShell Studio 2020
Operating system: Windows 10 1809
PowerShell version: v5.7.180
32 or 64 bit OS: 64-bit

As I start working with Pester, I am trying to adopt a new module structure where:
  • Each function resides in an individual .ps1 file in .\Functions\Public or .\Functions\Private.
  • The .psm1 file has a generic process that dot sources each of the public and private functions and exports the public functions (see below).
  • The Pester tests will either reside at .\Tests or .\Functions\Public\Tests or .\Functions\Private\Tests (I haven’t decided yet). They will also likely be broken into Unit and Integration folders, but again, that's not decided yet.
Module (.psm1) code:

Code: Select all

$PublicFunctions = @(Get-ChildItem -Path $PSScriptRoot\Functions\Public\*.ps1 -ErrorAction SilentlyContinue)
$PrivateFunctions = @(Get-ChildItem -Path $PSScriptRoot\Functions\Private\*.ps1 -ErrorAction SilentlyContinue)

foreach ($ScriptGroup in @($PublicFunctions, $PrivateFunctions)) {
    
    foreach ($ScriptFile in $ScriptGroup) {
        
        Try {
            Write-Debug "Importing $($ScriptFile.FullName)"
            . $ScriptFile.FullName
        }
        Catch {
            Write-Error -Message "Failed to import function $($_.ScriptFile.FullName)"
        }
    }
}

Export-ModuleMember -Function $PublicFunctions.Basename
Unfortunately, this method seems to prevent breakpoints in the individual .ps1 files from triggering. Breakpoints in the Test-Module.ps1 file still work, but even if I set a breakpoint there, then step into the .ps1 file, breakpoints in the .ps1 file are still completely ignored. Is there a way around this behavior? Is this a good module structure or do you prefer the 'standard' approach where all functions reside in the .psm1 file (or some other approach)? Thanks.

User avatar
Olga_B
Site Admin
Posts: 151
Joined: Mon May 15, 2017 9:06 am

Re: Dot Sourcing module functions seems to 'break' breakpoints

Post by Olga_B »

Thank you for the feedback. We are investigating this and will update you as soon as we have more information.

If you can, please zip and load up the original project file(s), so that we can attempt to recreate the issue:

https://www.sapien.com/support/upload

User avatar
brittneyr
Site Admin
Posts: 613
Joined: Thu Jun 01, 2017 7:20 am
Answers: 6
Been upvoted: 5 times

Re: Dot Sourcing module functions seems to 'break' breakpoints

Post by brittneyr »

We received your upload and were able to reproduce this issue. A bug report has been filed with the development team. This should be fixed in the next service release of PowerShell Studio.
Brittney Ryn
SAPIEN Technologies, Inc.

User avatar
brittneyr
Site Admin
Posts: 613
Joined: Thu Jun 01, 2017 7:20 am
Answers: 6
Been upvoted: 5 times

Re: Dot Sourcing module functions seems to 'break' breakpoints

Post by brittneyr »

Please try service build 5.7.182 and let me know if this is now working for you.
Brittney Ryn
SAPIEN Technologies, Inc.