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

Negative values provided to the Get-Content -Tail parameter no longer return the entire content, and instead print an error #21347

Closed
5 tasks done
AlexFolland opened this issue Mar 15, 2024 · 8 comments
Labels
Resolution-Answered The question is answered.

Comments

@AlexFolland
Copy link

AlexFolland commented Mar 15, 2024

Prerequisites

Steps to reproduce

Negative values for Get-Content parameter -Tail are no longer considered valid, despite the documentation specifying that the accepted type is Int32 which supports negative values, and that providing a negative value results in an unlimited number of lines, effectively showing the full content of the file regardless of its length, even if that length is above $([int]::MaxValue).

The latest documentation for this command says this in the -Tail section:

Negative values cause the cmdlet to return the entire contents.

So, it looks like the current behavior does not match the documented behavior.

I see no current equivalent way to guarantee getting a truly unlimited number of lines beyond $([int]::MaxValue). That returns a very large number, but does not guarantee all lines if the file has more lines than $([int]::MaxValue).

Expected behavior

PS> Get-Content ${filePath} -Wait -Tail -1
<full content of the file at ${filePath} shown here>

Observed behavior

PS> Get-Content ${filePath} -Wait -Tail -1
Get-Content: Cannot validate argument on parameter 'Tail'. The -1 argument is less than the minimum allowed range of 0. Supply an argument that is greater than or equal to 0 and then try the command again.

Error details

I am submitting this issue report on a different computer from the one in which I discovered this issue, so I don't have direct copy access to the output of Get-Error. The error says Get-Content: Cannot validate argument on parameter 'Tail'. The -1 argument is less than the minimum allowed range of 0. Supply an argument that is greater than or equal to 0 and then try the command again. though.

Environment data

I am submitting this issue report on a different computer from the one in which I discovered this issue, so I don't have direct copy access to the output of ${PSVersionTable}. It says the version is 7.4.1 though.

@AlexFolland AlexFolland added the Needs-Triage The issue is new and needs to be triaged by a work group. label Mar 15, 2024
@rhubarb-geek-nz
Copy link

rhubarb-geek-nz commented Mar 15, 2024

That returns a very large number, but does not guarantee all lines if the file has more lines than $([int]::MaxValue).

Just to put in perspective

PS> [int]::MaxValue
2147483647

so that is 2,147,483,647

There are only 783,137 words in the King James bible and the Linux kernel is of the order of 30 million lines across all files.

@AlexFolland
Copy link
Author

AlexFolland commented Mar 15, 2024

Still, if almost every character is a line break, that's only a 2 GiB file. I have dealt with logs in the hundreds of gigabytes before, and introducing an arbitrary limitation when there previously wasn't one is a regression, regardless of perspective. Also, the behavior not matching the documentation is itself an issue.

@AlexFolland
Copy link
Author

AlexFolland commented Mar 15, 2024

The fact is that there's a regression and the behavior doesn't match the documentation. That's the purpose of the report. Please stop commenting on this issue if the comments are not intended to further the issue's resolution.

Edit: There was a comment above this after my previous comment, but it seems to have been deleted.

@MartinGC94
Copy link
Contributor

The change was made here: #19715 looking at the old code it seems that there was never any reason to specify a negative number because if you did then it would just read it from start to finish, as if you hadn't specified Tail at all. So for the statement/question:

I see no current equivalent way to guarantee getting a truly unlimited number of lines

The answer seems to be to just not specify Tail at all.

@AlexFolland
Copy link
Author

AlexFolland commented Mar 15, 2024

OK, thanks. I've tested that, and it does seem to work as desired. I'll update my command to omit -Tail and its value. My particular use case is solved, but the issue with the documentation remains.

It sounds like the resolution for this issue, then, is to update the documentation to remove the reference to using a negative value, and possibly suggest omitting -Tail to accomplish the desired behavior.

@mklement0
Copy link
Contributor

I've created a docs issue:

@SteveL-MSFT SteveL-MSFT added Resolution-Answered The question is answered. and removed Needs-Triage The issue is new and needs to be triaged by a work group. labels Mar 18, 2024
@AlexFolland
Copy link
Author

The documentation change does not suggest omitting -Tail to accomplish the desired behavior to bridge the gap for users who previously passed a negative value to -Tail, but those users can find this ticket if they need to. Either way, this issue is now technically resolved, so I'm closing it. Thanks for the effort!

@AlexFolland
Copy link
Author

AlexFolland commented Mar 19, 2024

📣 Hey @AlexFolland, how did we do? We would love to hear your feedback with the link below! 🗣️

🔗 https://aka.ms/PSRepoFeedback

Microsoft Forms

I already gave my feedback in the ticket. If someone cares about it, they can read the ticket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution-Answered The question is answered.
Projects
None yet
Development

No branches or pull requests

5 participants