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

Start-GSDriveFileUpload throws Exception setting "CursorVisible": "The handle is invalid on ps jobs #242

Closed
DCurtin opened this issue Oct 6, 2019 · 6 comments
Assignees
Labels

Comments

@DCurtin
Copy link

DCurtin commented Oct 6, 2019

Describe the bug
Exception thrown
Exception setting "CursorVisible": "The handle is invalid.
when running Start-GSDriveFileUpload in a ps job
To Reproduce
Steps to reproduce the behavior:
$newJob = Start-Job -ScriptBlock {Start-GSDriveFileUpload -Path $args[0] -Parents @('some-parent-id') -Verbose} -ArgumentList @('filepath');

Expected behavior
CursorVisble exception to not be thrown?
The file seems to upload successfully regardless. So it's not terribly important, just annoying

Environment (please complete the following information):

  • OS: Windows 10 1809
  • PowerShell Version: Windows PowerShell 5.1
  • PSGSuite Version: 2.33

Additional context
When running get-host on a job this is returned

Name : ServerRemoteHost
Version : 1.0.0.0
InstanceId : 0c466ab7-b486-42fc-af7e-2dc2a99a2617
UI : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture : en-US
CurrentUICulture : en-US
PrivateData :
DebuggerEnabled : True
IsRunspacePushed : False
Runspace : System.Management.Automation.Runspaces.LocalRunspace

On line 328 and 221 of https://github.com/scrthq/PSGSuite/blob/master/PSGSuite/Public/Drive/Start-GSDriveFileUpload.ps1

It's setting [System.Console]::CursorVisible = $true when $host.name Is not PS ISE
maybe ServerRemoteHost needs to be added to the filter?

@scrthq
Copy link
Member

scrthq commented Oct 7, 2019

hey @DCurtin - Thanks for opening this up! I think to catch all scenarios, I can wrap the call to [System.Console]::CursorVisible in a try/catch block with the catch just being empty (and possibly removing that error from the $global:Error array as well)

It seems to catch as expected here:

Start-Job {
    try {
        [System.Console]::CursorVisible = $true
    }
    catch {
        "Couldn't be set"
    }
} | Wait-Job | Receive-Job

Thoughts?

@scrthq
Copy link
Member

scrthq commented Oct 7, 2019

Also worth noting that Start-GSDriveFileUpload will kick off background jobs by default if you don't include the -Wait parameter, IIRC.

scrthq added a commit that referenced this issue Oct 7, 2019
## 2.33.2 - 2019-10-06

* [Issue #242](#242)
    * Fixed: Error handling around `[System.Console]::CursorVisible` on `Start-GSDriveFileUpload`, `Wait-GSDriveFileUpload` and `Write-InlineProgress`
    * Cleaned up verbose handling on `Stop-GSDriveFileUpload` due to file uploads showing as Failed even though they were successful.
* Miscellaneous
    * Updated build.ps1 script for better verbose output
scrthq added a commit that referenced this issue Oct 7, 2019
## 2.33.2 - 2019-10-06

* [Issue #242](#242)
    * Fixed: Error handling around `[System.Console]::CursorVisible` on `Start-GSDriveFileUpload`, `Wait-GSDriveFileUpload` and `Write-InlineProgress`
    * Cleaned up verbose handling on `Stop-GSDriveFileUpload` due to file uploads showing as Failed even though they were successful.
* Miscellaneous
    * Updated build.ps1 script for better verbose output
@scrthq
Copy link
Member

scrthq commented Oct 7, 2019

hey @DCurtin - Fix added and deployed in PSGSuite v2.33.2, you should no longer see that pesky error! Let me know if all is well =]

@scrthq scrthq self-assigned this Oct 7, 2019
@scrthq scrthq added the bug label Oct 7, 2019
@DCurtin
Copy link
Author

DCurtin commented Oct 7, 2019

awesome, I noticed that about it kicking off background jobs. I likely don't need to wrap it in a job but wanted a way to manage sets in a more custom way.

Really appreciate this project.

@DCurtin
Copy link
Author

DCurtin commented Oct 7, 2019

All's well, thank you for the update.

@DCurtin DCurtin closed this as completed Oct 7, 2019
@scrthq
Copy link
Member

scrthq commented Oct 7, 2019

Yup! It starts them as async requests in background threads. You can check on the status at any time with Get-GSDriveFileUploadStatus as well, in case you want visibility at the forefront. Using a PS Job may obscure that a bit since you don't really have the ability to invoke a new command in the existing Job afaik, so you're leaving it up to chance at that point IMO. With a shaky internet connection, it may be a bit risky, even with the built-in failure retry mechanism

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants