darkoperator / darkoperator/Posh-SSH

Get-SFTPItem does not throw on error

Open
#606 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PowerShell
Stars
1.1k
Forks
222
PR merge metrics
No merged PRs in 30d

Description

The CmdLet Get-SFTPItem does not throw a terminating error on failure, it only displays a warning. The $error variable isn't even populated, so it seems like nothing happened.

This is a big issue for us, as we can't handle exceptions like big files failing because of disk full, connection interruptions, ...

Or maybe I'm missing something?

try {
    $params = @{
       SessionId = 1
        Path        = '\bigFile.mpg'
        Destination = 'c:\bigFile.mpg'
    }
    Get-SFTPItem @params -ErrorAction Stop
}
catch {
   "Error: $_" # we should end up here on failure, but we don't
}

function New-BigFileHC {
    Param (
        [string]$Path = 'c:\bigFile.txt',
        [int]$SizeInGB = 10
    )
    $sizeInBytes = $SizeInGB * 1GB

    $fs = [System.IO.File]::Create($Path)
    $fs.SetLength($sizeInBytes)
    $fs.Close()
}

Image

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the Get-SFTPItem implementation and reproduce the reported failure with -ErrorAction Stop using the example parameters. Trace the failed transfer path and verify that a disk-full or connection error becomes a terminating error and populates $error, then rerun the try/catch example to confirm the catch block is reached.

Written by the indexing model from the issue text.

Assessment

Tech stack
powershell
Domain
cli, networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.