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

Documentation on how to debug #138

Open
blitzmann opened this issue Aug 20, 2021 · 9 comments
Open

Documentation on how to debug #138

blitzmann opened this issue Aug 20, 2021 · 9 comments
Labels
help wanted Extra attention is needed

Comments

@blitzmann
Copy link
Contributor

I would like to be able to debug the cmdlets so that I can have better insight into errors / posssible help contribute. I used to know how, but that knowledge has been lost to time. It would be nice if that information was available via a Developer Getting Started wiki page

@sanderstad
Copy link
Collaborator

That is certainly possible. I will work on that to get something going but it has been very busy lately

@DatKyle
Copy link

DatKyle commented Aug 22, 2021

It is not true debugging but you can specify -Verbose which gives you a good indication of whats happening. It is what I have been using to identify and resolve issues.
Could also add -WhatIf to prevent the module from making changes.

@blitzmann
Copy link
Contributor Author

It's something, and it's what I've resorted to before, but I'm looking for true debugging and how to run a local copy within VS Code without affecting any installed copy, so that I can make tweaks and put breakpoints, etc.

@sanderstad
Copy link
Collaborator

I'm not sure how to help you with this because I debug it the same way by putting in debug messages where things possible go wrong and fix it that way.
If you have an idea how to do that feel free to look into that and make a solution for that so that we can use improve debugging for the module.

@sanderstad sanderstad added the help wanted Extra attention is needed label Sep 9, 2021
@blitzmann
Copy link
Contributor Author

Even just some information on how you run this locally without having to install it, so that I can add print statements, run it and see what happens. But I'm running into issues there as well. Here's my steps so far:

  • Clone repo
  • Open Powershell in admin
  • Install dependancies:
    • Install-Module PSFramework
    • Install-Module dbatools
  • Import-Module .\dbaclone.psd1 -force

This produces

WARNING: [23:41:27][Get-DcnClone] The module setup has NOT yet successfully run. Please run 'Set-DcnConfiguration'
WARNING: [23:41:27][Get-DcnImage] The module setup has NOT yet successfully run. Please run 'Set-DcnConfiguration'
WARNING: [23:41:27][<Unknown>] The module is not yet configured. Please run Set-DcnConfiguration to make the neccesary changes
Exception calling "InvokeScript" with "4" argument(s): "You cannot call a method on a null-valued expression."
At C:\gitRoot\dbaclone\dbaclone.psm1:49 char:9
+     else { $ExecutionContext.InvokeCommand.InvokeScript($false, ([scr ...
+            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : CmdletInvocationException

Any insight? I can compile any findings into a wiki page or a DEVELOPER.md file and PR it.

@DatKyle
Copy link

DatKyle commented Sep 17, 2021

I've done some digging and found an old Reddit post by yourself (@blitzmann):
Reddit - VSCode: How to debug a function inside a module
Based on the top comment about $doDotSource, I made a debug.ps1 file which seems to work:

# Sets $doDotSource to true.
$dbaclone_dotsourcemodule = $true;
Import-Module .\dbaclone.psd1 -Force

# Configure DbaClone to use a SQL Store
$username = "sa"
$password = ConvertTo-SecureString -AsPlainText "Pass@word!" -Force
$sqlCredential = New-Object System.Management.Automation.PSCredential -ArgumentList ($username, $password)
$sqlInstance = "localhost"
Set-DcnConfiguration -InformationStore SQL -SqlInstance $sqlInstance -SqlCredential $sqlCredential

# Command to debug
Get-DcnImage

If your using VS code I used the below launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "PowerShell: Launch Current File",
            "type": "PowerShell",
            "request": "launch",
            "script": ".\\debug.ps1",
            "cwd": ""
        }
    ]
}

@DatKyle
Copy link

DatKyle commented Sep 24, 2021

@blitzmann have you had a chance to try out the above?

@blitzmann
Copy link
Contributor Author

@DatKyle I have not yet, but I'm looking forward to it. I plan to check it out on Friday when I can get back t this project

@blitzmann
Copy link
Contributor Author

@DatKyle sorry for the delay, I finally got a change to start looking into this stuff again. It does seem to work at first glance, would be nice if I could debug while issuing commands in the console, but this is a good start. I'll play around with it some more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants