Skip to content

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

Open

Description

@bcwilhite

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

Activity

  1. jcwalker commented on Aug 16, 2019

    @jcwalker
    Contributor

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

  2. added
    bug
    help wanted
    on Apr 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bughelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions