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.
This topic is 3 years and 5 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
User avatar
HONDAAL
Posts: 15
Last visit: Wed Dec 22, 2021 10:02 am
Has voted: 1 time

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: 196
Last visit: Thu Mar 28, 2024 8:34 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: 1655
Last visit: Thu Mar 28, 2024 3:14 pm
Answers: 39
Been upvoted: 30 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
SAPIEN Technologies, Inc.
User avatar
brittneyr
Site Admin
Posts: 1655
Last visit: Thu Mar 28, 2024 3:14 pm
Answers: 39
Been upvoted: 30 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
SAPIEN Technologies, Inc.
This topic is 3 years and 5 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.