- Notifications
You must be signed in to change notification settings - Fork7.7k
FixStart-Transcript
error when$Transcript
is aPSObject
wrapped string#24963
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Start-Transcript | ||
Write-Host -Message $message -InformationAction Ignore | ||
Stop-Transcript | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Can we use ValidateTranscription function?
kborowinskiFeb 6, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Not without a bit of refactoring. We would need to implement extra support just for this case, so I have chosen to follow similar existing tests, like:
It"Transcription should record Write-Host output when InformationAction is set to SilentlyContinue" { [String]$message=New-Guid$script= {Start-Transcript-Path$transcriptFilePathWrite-Host-Message$message-InformationAction SilentlyContinueStop-Transcript }&$script$transcriptFilePath| Should-Exist$transcriptFilePath| Should-FileContentMatch$message }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Why won't it work?
$script="Start-Transcript"$outputFilePath= expected_file_path ValidateTranscription-scriptToExecute$script-outputFilePath$outputFilePath
kborowinskiFeb 6, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I need to test ifPSObject
wrapped string in$Transcript
preference variable works withStart-Transcript
. This will not work, because when$Transcript
is not defined, theStart-Transcript
will create the transcript file automatically either in:
- on Windows:
$HOME\Documents
- on Linux or macOS:
$HOME
and unwrapping will not be tested at all.
I would have to refactorValidateTranscription
to support this case. It would need to be something like this:
$ps.AddScript({param([PSObject]$filePath)$Global:Transcript=$filePath}).AddArgument($outputFilePath).Invoke()
plus some extra logic to handle this case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
$script="$Global:Transcript = testfile; Start-Transcript"$outputFilePath= expected_file_path ValidateTranscription-scriptToExecute$script-outputFilePath$outputFilePath
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
OK, now you are just flexing 😂, how did I miss that 😉
BTW,Pester does not like this:
It"Should create Transcript file with 'Transcript' preference variable" {$script="$Global:Transcript =$transcriptFilePath; Start-Transcript" ValidateTranscription-scriptToExecute$script-outputFilePath$transcriptFilePath}
Thankfully, this works:
It"Should create Transcript file with 'Transcript' preference variable" {$script="Set-Variable -Scope Global -Name Transcript -Value$transcriptFilePath; Start-Transcript" ValidateTranscription-scriptToExecute$script-outputFilePath$transcriptFilePath}
Will update PR ASAP.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
One more change. We need to cast the$transcriptFilePath
string to thePSObject
, otherwise it defeats the purpose:
It"Should create Transcript file with 'Transcript' preference variable" {$script="Set-Variable -Scope Global -Name Transcript -Value ([PSObject]'$transcriptFilePath'); Start-Transcript" ValidateTranscription-scriptToExecute$script-outputFilePath$transcriptFilePath}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I'd expect if we assign to psvariable it is already wrapped in PSObject. It seems the original issue is about this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Yeah, when you assign it does, but when you useSet-Variable
it does not. I had to do the cast, otherwise the test was passing on current release without fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Please add a comment in the test line to exclude regression.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
0beb24e
intoPowerShell:masterUh oh!
There was an error while loading.Please reload this page.
microsoft-github-policy-servicebot commentedFeb 7, 2025 • edited by unfurl-linksbot
Loading Uh oh!
There was an error while loading.Please reload this page.
edited by unfurl-linksbot
Uh oh!
There was an error while loading.Please reload this page.
📣 Hey@kborowinski, how did we do? We would love to hear your feedback with the link below! 🗣️ 🔗https://aka.ms/PSRepoFeedback |
PR Summary
Fix#24740
PR Context
Unwrap transcript filename stored as
PSObject
in$Transcript
preference variable.PR Checklist
.h
,.cpp
,.cs
,.ps1
and.psm1
files have the correct copyright headerWIP:
or[ WIP ]
to the beginning of the title (theWIP
bot will keep its status check atPending
while the prefix is present) and remove the prefix when the PR is ready.- [ ] Issue filed:
(which runs in a different PS Host).