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

ReplaceText: Exception calling "Matches" error when text file is blank/empty #38

Open
bcwilhite opened this issue Aug 15, 2019 · 1 comment
Labels
bug The issue is a bug. help wanted The issue is up for grabs for anyone in the community.

Comments

@bcwilhite
Copy link

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

When using the ReplaceText DSC resource in order to Append Text to a blank/empty text file, the resource throws an error "Exception calling "Matches" with "2" argument(s): "Value cannot be null. Parameter name: input"

Verbose logs showing the problem

image

Suggested solution to the issue

Enable the resource to handle blank/empty file scenarios. The issue occurs due to $fileContent having a null value, which is expected when the file is blank.

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

configuration BlankFileScenario
{
    Import-DscResource -ModuleName FileContentDsc

    node localhost
    {
        ReplaceText "BlankEmpty File"
        {
            Path        = 'C:\Dev\blankFile.txt' #blank file -> Get-Content should be true when compared to $null
            Search      = 'search'
            Type        = 'Text'
            Text        = 'replacement'
            AllowAppend = $true
        }
    }
}

The operating system the target node is running

Windows Server 2012 R2

Version and build of PowerShell the target node is running

5.1.14409.1018

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

1.1.0.108

@jcwalker
Copy link
Contributor

I would like to add that this error is thrown in Test-TargetResource at line 280.

@PlagueHO PlagueHO added bug The issue is a bug. help wanted The issue is up for grabs for anyone in the community. labels Apr 14, 2020
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. help wanted The issue is up for grabs for anyone in the community.
Projects
None yet
Development

No branches or pull requests

3 participants