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

KeyValuePairFile: Unable to insert into empty file. #34

Closed
zack-is-cool opened this issue Jul 16, 2019 · 3 comments · Fixed by #35
Closed

KeyValuePairFile: Unable to insert into empty file. #34

zack-is-cool opened this issue Jul 16, 2019 · 3 comments · Fixed by #35
Assignees
Labels
bug The issue is a bug. in progress The issue is being actively worked on by someone.

Comments

@zack-is-cool
Copy link

zack-is-cool commented Jul 16, 2019

Details of the scenario you tried and the problem that is occurring

Hi, I was trying to run KeyValuePairFile from FileContentDsc on an empty .config file to try to populate some new entries. Not sure if this is supported or not or if I should be using a different DSC resource, but I kept getting errors, I'm assuming because the file was empty and everything the DSC resource was trying to work with was null.

Realistically, for what I'm going to be using this for, I won't be having this issue. Just figured I'd bring it up since I ran into it.

Verbose logs showing the problem

This was in my event viewer for operational DSC logs:

Event 4252 -
Job {43432191-A78D-11E9-837E-408D5C58C088} :
MIResult: 1
Error Message: Exception calling "Matches" with "3" argument(s): "Value cannot be null.
Parameter name: input"
Message ID: ArgumentNullException
Error Category: 0
Error Code: 1
Error Type: MI

From Get-DscConfigurationStatus -

Get-DscConfigurationStatus | select -ExpandProperty ResourcesnotInDesiredState


ConfigurationName    : splunkServerConfconfig
DependsOn            :
ModuleName           : FileContentDsc
ModuleVersion        : 1.1.0.108
PsDscRunAsCredential :
ResourceId           : [KeyValuePairFile]splunkServerConf_serverCert
SourceInfo           : ::15::9::KeyValuePairFile
DurationInSeconds    : 0.067
Error                : {
                           "Exception":  {
                                             "Message":  "The PowerShell DSC resource \u0027[KeyValuePairFile]splunkServerConf_serverCert\u0027 with SourceInfo \u0027::15::9::KeyValuePairFile\u0027 threw one or more non-terminating
                       errors while running the Test-TargetResource functionality. These errors are logged to the ETW channel called Microsoft-Windows-DSC/Operational. Refer to this channel for more details.",
                                             "Data":  {

                                                      },
                                             "InnerException":  null,
                                             "TargetSite":  null,
                                             "StackTrace":  null,
                                             "HelpLink":  null,
                                             "Source":  null,
                                             "HResult":  -2146233079
                                         },
                           "TargetObject":  null,
                           "CategoryInfo":  {
                                                "Category":  7,
                                                "Activity":  "",
                                                "Reason":  "InvalidOperationException",
                                                "TargetName":  "",
                                                "TargetType":  ""
                                            },
                           "FullyQualifiedErrorId":  "NonTerminatingErrorFromProvider",
                           "ErrorDetails":  null,
                           "InvocationInfo":  null,
                           "ScriptStackTrace":  null,
                           "PipelineIterationInfo":  [

                                                     ]
                       }
FinalState           :
InDesiredState       : False
InitialState         :
InstanceName         : splunkServerConf_serverCert
RebootRequested      : False
ResourceName         : KeyValuePairFile
StartDate            : 7/15/2019 11:01:41 PM
StateChanged         : False
PSComputerName       :


ConfigurationName    : splunkServerConfconfig
DependsOn            :
ModuleName           : FileContentDsc
ModuleVersion        : 1.1.0.108
PsDscRunAsCredential :
ResourceId           : [KeyValuePairFile]splunkServerConf_sslPassword
SourceInfo           : ::24::9::KeyValuePairFile
DurationInSeconds    : 0.01
Error                : {
                           "Exception":  {
                                             "Message":  "The PowerShell DSC resource \u0027[KeyValuePairFile]splunkServerConf_sslPassword\u0027 with SourceInfo \u0027::24::9::KeyValuePairFile\u0027 threw one or more non-terminating
                       errors while running the Test-TargetResource functionality. These errors are logged to the ETW channel called Microsoft-Windows-DSC/Operational. Refer to this channel for more details.",
                                             "Data":  {

                                                      },
                                             "InnerException":  null,
                                             "TargetSite":  null,
                                             "StackTrace":  null,
                                             "HelpLink":  null,
                                             "Source":  null,
                                             "HResult":  -2146233079
                                         },
                           "TargetObject":  null,
                           "CategoryInfo":  {
                                                "Category":  7,
                                                "Activity":  "",
                                                "Reason":  "InvalidOperationException",
                                                "TargetName":  "",
                                                "TargetType":  ""
                                            },
                           "FullyQualifiedErrorId":  "NonTerminatingErrorFromProvider",
                           "ErrorDetails":  null,
                           "InvocationInfo":  null,
                           "ScriptStackTrace":  null,
                           "PipelineIterationInfo":  [

                                                     ]
                       }
FinalState           :
InDesiredState       : False
InitialState         :
InstanceName         : splunkServerConf_sslPassword
RebootRequested      : False
ResourceName         : KeyValuePairFile
StartDate            : 7/15/2019 11:01:41 PM
StateChanged         : False
PSComputerName       :

The DSC configuration that is used to reproduce the issue (as detailed as possible)

Configuration splunkServerConfconfig 
{
    
    [Cmdletbinding()]
    param
    (
        [parameter()]
        [string[]]
        $NodeName = 'localhost'
    )
    Import-DscResource -ModuleName FileContentDsc

    Node $NodeName
    {
        KeyValuePairFile splunkServerConf_serverCert
        {
            Path = "B:\Code\GitHub\PowerShell\SplunkDSCTest\server.conf"
            Name = "serverCert"
            Text = "B:\fakecert.pem"
            Type = "Text"
            Ensure = "Present"
        }
        
        KeyValuePairFile splunkServerConf_sslPassword
        {
            Path = "B:\Code\GitHub\PowerShell\SplunkDSCTest\server.conf"
            Name = "sslPassword"
            Text = "passwordpassword"
            Type = "Text"
            Ensure = "Present"
        }
    }
}

Version and build of PowerShell the target node is running

Name Value


PSVersion 5.1.17763.592
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17763.592
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

Version of the DSC module that was used ('dev' if using current dev branch)

1.1.0.108

@PlagueHO PlagueHO added needs investigation The issue needs to be investigated by the maintainers or/and the community. bug The issue is a bug. help wanted The issue is up for grabs for anyone in the community. and removed needs investigation The issue needs to be investigated by the maintainers or/and the community. labels Jul 16, 2019
@PlagueHO
Copy link
Member

Hi @ActionN - thanks for raising this. It does indeed look like a bug: The resource does not create the file if it does not exist. But it should - so I'll fix this ASAP. I'm snowed under at work for the next two days but I'll try and get to this Thursday night. It should be a fairly straight forward fix, but I'll need to add some integration tests to ensure it's fixed correctly.

@PlagueHO PlagueHO self-assigned this Jul 16, 2019
@zack-is-cool
Copy link
Author

zack-is-cool commented Jul 16, 2019

Well, in my case the file did exist. It was just completely empty and didn't have any text in it.

I see what you're saying though, you'd run into a similar road block if the file didn't exist yet.

@PlagueHO PlagueHO added in progress The issue is being actively worked on by someone. and removed help wanted The issue is up for grabs for anyone in the community. labels Jul 17, 2019
@PlagueHO
Copy link
Member

Just working on this now.

PlagueHO added a commit that referenced this issue Jul 20, 2019
Fix error when KeyValuePair file is empty or does not exist - Fixes #34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug The issue is a bug. in progress The issue is being actively worked on by someone.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants