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

Errors on Import #191

Closed
4 tasks done
lowlydba opened this issue May 2, 2022 · 6 comments
Closed
4 tasks done

Errors on Import #191

lowlydba opened this issue May 2, 2022 · 6 comments

Comments

@lowlydba
Copy link
Contributor

lowlydba commented May 2, 2022

Before submitting the bug

  • Ensure you are able to reproduce it on the latest released version (we release often)
  • Verified this bug is not already reported in an issue
  • Verified errors are not related to permissions
  • Can reproduce in a clean PowerShell session (clean = powershell -NoProfile)

Describe the bug
I haven't been able to dig in much deeper yet, but after having used Set-DcnConfiguration to point to a valid dbaclone database, the following error appears on Import-Module dbaclone. It appears to work fine after the error and doesn't happen 100% of the time.

To Reproduce

PS C:\> Import-Module dbaclone -VErbose
VERBOSE: Loading module from path 'C:\Program Files\WindowsPowerShell\Modules\dbaclone\0.10.63\dbaclone.psd1'.
VERBOSE: Populating RepositorySourceLocation property for module dbaclone.
VERBOSE: Loading module from path 'C:\Program Files\WindowsPowerShell\Modules\dbaclone\0.10.63\dbaclone.psm1'.
WARNING: [13:57:06][Get-DcnClone] Something is wrong in the module configuration | Cannot convert value "xxxx.xx.com" to type "Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter". Error: "Failed to
interpret input as Instance: xxxx.xx.com"
Exception calling "InvokeScript" with "4" argument(s): "Exception calling "InvokeScript" with "4" argument(s): "Cannot convert value "xxxx.xx.com" to type
"Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter". Error: "Failed to interpret input as Instance: xxxx.xx.com"""
At C:\Program Files\WindowsPowerShell\Modules\dbaclone\0.10.63\dbaclone.psm1:49 char:9

Expected behavior
A clean import.

@blitzmann
Copy link
Contributor

I can confirm that this has been an issue

@sanderstad
Copy link
Collaborator

With the latest version of dbaclone 0.10.65 (released today) this should be a thing of the past

@lowlydba
Copy link
Contributor Author

lowlydba commented May 5, 2022

Haven't tested extensively yet, but so far so good on the new version. Thanks!

@lowlydba lowlydba closed this as completed May 5, 2022
@lowlydba lowlydba reopened this Jun 27, 2022
@lowlydba lowlydba reopened this Jun 27, 2022
@lowlydba
Copy link
Contributor Author

Unfortunately, I'm still seeing this on a brand new server with v 0.10.68.

If Set-DcnConfiguration has not been run, the error received is below. If it has been run, the error is the same as the original posted.

WARNING: [10:30:03][Get-DcnClone] The module setup has NOT yet successfully run. Please run 'Set-DcnConfiguration'
WARNING: [10:30:03][Get-DcnImage] The module setup has NOT yet successfully run. Please run 'Set-DcnConfiguration'
Exception calling "InvokeScript" with "4" argument(s): "You cannot call a method on a null-valued expression."
At C:\Program Files\WindowsPowerShell\Modules\dbaclone\0.10.68\dbaclone.psm1:49 char:9
+     else { $ExecutionContext.InvokeCommand.InvokeScript($false, ([scr ...
+            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : RuntimeException

@ay-azara
Copy link

ay-azara commented Oct 13, 2023

Alright, the issue still present but I do have a workaround for you.

TLDR

Run Set-PSFConfig -Module dbaclone -Name informationstore.mode -Value 'SQL'.

The long version

To recap, these are the errors and, for me, they started while I was trying to call New-DcnImage

WARNING: [15:19:54][Get-DcnClone] The module setup has NOT yet successfully run. Please run 'Set-DcnConfiguration'
WARNING: [15:19:54][Get-DcnImage] The module setup has NOT yet successfully run. Please run 'Set-DcnConfiguration'

The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Exception calling "InvokeScript" with "4"       
argument(s): "You cannot call a method on a null-valued expression."
Exception calling "InvokeScript" with "4" argument(s): "You cannot call a method on a null-valued expression."

This led to another issue where the module couldn't be imported.

Set-DcnConfiguration : The 'Set-DcnConfiguration' command was found in the module 'dbaclone', but the module could not be loaded. For more information, run 
'Import-Module dbaclone'.

Looking at $Error it seemed to be for the same reason as above, just buried. The solution of running Set-DcnConfiguration became an impossible chicken/egg scenario.

So, time to open up VSCode, create a file with Import-Module Dbaclone, set the debugger on that line and start debugging.

We step inside Import-Module and keep stepping over until we hit an error. VSCode will automatically open up the Dbaclone files as we continue.

dbaclone\0.10.72\dbaclone.psm1
L49: else { $ExecutionContext.InvokeCommand.InvokeScript($false, ([scriptblock]::Create([io.file]::ReadAllText($resolvedPath))), $null, $null) }

This statement is failing so we update the breakpoint and start over but this time we step inside and keep stepping over until we hit the next error.

dbaclone\0.10.72\internal\scripts\postimport.ps1
L25: if (((Get-PSFConfigValue -FullName dbaclone.informationstore.mode).ToLower()) -eq 'file') {

As you can see, this function is leveraging the Powershell Framework's PSFConfig functions to get/set Dbaclone config settings. If we run the snippet Get-PSFConfigValue -FullName dbaclone.informationstore.mode we find that the value is empty. I don't know how this occurred and I'm unlikely to look deeper into it but the solution is clear, manually setting it with Set-PSFConfig -Module dbaclone -Name informationstore.mode -Value 'SQL'.

And there you have. In my case I'm using SQL. If you're using something else use that. I'm not sure how the module loads after install before you run Set-DcnConfiguration but that's a question for another day).

@lowlydba
Copy link
Contributor Author

lowlydba commented Oct 15, 2023

Thanks for the followup on this! I am no longer working where this was a problem, but this makes sense enough to unblock them I'm sure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants