none
Function always returns true RRS feed

  • Question

  • I have a function that is always returning true. I have a basic understanding of the idea that the pipeline can get polluted, so I created a separate function that just returns false, and I can put this snippet anywhere to test.

    Write-Host "$(Test-PxPipeline)!"

    If I understand right, if I have polluted the pipeline, this should come back with something other than false. Based on that assumption, I have done 

    1: Set the variable that will contain the Return value to $Null immediately before the function call
    2: Test the value of the variable before and after the call.
    3: Test the value of the return variable in the function
    4: Test the pipeline before and after all of the above

    Still, return is always True. I even went so far as to make the last line of the function Return $False, still the variable the function return is assigned to is true.

    Also, this is happening in multiple similar functions, with a fair amount of shared code, so tracking down the culprit is proving difficult.

    So, first question. Is my understanding of the pipeline pollution issue flawed? Is my little test function really not showing me any meaningful information?

    And second, is there any suggestion of what I should be looking for? Or is this one of those things with numerous potential causes and I need to just start eliminating functions till it works, and then eliminate code within that function? 

    One last note, right now this is all script code driven by shortcut arguments, but if I could monitor the pipeline with a breakpoint in the ISE I could make that happen. The issue is I would need, I guess, a breakpoint on every write to $_, which seems like it is going to be a tone of breakpoints. Maybe an unmanageable number.

    In any case, any help is greatly appreciated. Thanks!


    Saturday, July 5, 2014 10:31 AM

Answers

  • We'll need to see a code sample demonstrating the the problem to give you a good diagnosis.  From the description I suspect it may be more of a issue of variable scope than pipeline pollution.

    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

    Saturday, July 5, 2014 10:52 AM
  • I hadn't heard of the term "pipeline pollution" until just now. mjolinor could be right that yours is more of a scope problem, but without seeing the actual offending code it is hard to determine which is the case. David Wyatt blogged on this and gives a method for tracking down the source of pipeline pollution that might be of help here.


    Al Dunbar -- remember to 'mark or propose as answer' or 'vote as helpful' as appropriate.

    Saturday, July 5, 2014 3:47 PM

All replies

  • We'll need to see a code sample demonstrating the the problem to give you a good diagnosis.  From the description I suspect it may be more of a issue of variable scope than pipeline pollution.

    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

    Saturday, July 5, 2014 10:52 AM
  • I hadn't heard of the term "pipeline pollution" until just now. mjolinor could be right that yours is more of a scope problem, but without seeing the actual offending code it is hard to determine which is the case. David Wyatt blogged on this and gives a method for tracking down the source of pipeline pollution that might be of help here.


    Al Dunbar -- remember to 'mark or propose as answer' or 'vote as helpful' as appropriate.

    Saturday, July 5, 2014 3:47 PM
  • It might also be confusion/misunderstanding about how boolean tests work.  If he's returning the literal string 'false' and then doing a boolean test on that, it will come back True.

    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

    Saturday, July 5, 2014 4:35 PM