Giter Site home page Giter Site logo

Comments (5)

sbergwall avatar sbergwall commented on August 21, 2024

Hi @WiredSharp.

Can you please send the text that is not parsed?

from robocopyps.

WiredSharp avatar WiredSharp commented on August 21, 2024

Hello,
here is an InputObject raising the previously mentioned error:
' 424 2022/10/11 13:40:54 E:\projects\Jee\lo.tools.jee\Tmp\modules\LO.Core\2.1.0\security\private\New-Credential2.ps1'

Notice that line has leading mix of tabs and spaces

BeforeDiscovery {
    $ModuleName = 'RobocopyPS'
    $ModuleBase = Split-Path -Parent $PSScriptRoot
    $ModulePath = Join-Path $ModuleBase -ChildPath $ModuleName

    # Removes all versions of the module from the session before importing
    Get-Module $ModuleName | Remove-Module
    Import-Module $ModulePath -PassThru -ErrorAction Stop
}
Describe "when parsing robocopy output" {
    InModuleScope $ModuleName {
        It "should not raise exception when parsing fails" -ForEach @(
            @{ line = '	  		     424 2022/10/11 13:40:54	E:\projects\New-Credential2.ps1';Source='E:\projects\New-Credential2.ps1' }
        ) {
            { Invoke-RobocopyParser -InputObject $line } | Should -Not -Throw
        }
    }
}

from robocopyps.

skaravos avatar skaravos commented on August 21, 2024

Another case that will trigger this same code path occurs when specifying a logfile that resides inside the 'Source' directory.
(***Normally you wouldn't put the log in the source dir, but when copying a single file it's technically safe)

For example:

Invoke-Robocopy -Source "C:\tmp\src" -Destination "C:\tmp\dst" -Files "abc.txt" -LogFile "C:\tmp\src\robocopy.log" -Force

The first line of output from robocopy.exe is something akin to:

 Log File : C:\tmp\src\robocopy.log

Because this log file line matches *$Source* it enters the wrong branch and triggers the 'You cannot call a method on a null-valued expression.'
The offending line is here:

ElseIf ($InputObject -like "*$($Source.Replace('[','`[').Replace(']','`]'))*") {

I've only briefly tested @WiredSharp's PR, but it seems to work perfectly and has also inadvertently solved this logfile bug!

from robocopyps.

sbergwall avatar sbergwall commented on August 21, 2024

Hi.

This is merged to master in Github, will push it to the Powershell Gallery as soon as possible. Thank you @WiredSharp for your help, much appreciated!

from robocopyps.

sbergwall avatar sbergwall commented on August 21, 2024

Hi.

This is now released to Powershell Gallery with version 0.2.19.

from robocopyps.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.