darkoperator / darkoperator/Posh-SSH

Get-SFTPChildItem does not throw an error

Open
#607 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-ChildItem does not throw a terminating error when the path is not found and ErrorAction = 'Stop'

try {
    Get-SFTPChildItem @sessionParams -Path '/notExstingPath' -Recurse -ErrorAction Stop
   # displays error but does not end up in the catch clause:
   # Error listing items in /notExstingPath: Exception calling "ListDirectory" with "1" argument(s): "No such file"
}
catch {
    "Oops: $_"
}
workaround
try {
    $errorMessage = $null

    Get-SFTPChildItem @sessionParams -Path '/notexsting' -Recurse -EA Stop -ErrorVariable 'errorMessage'

    if($errorMessage) {
        throw $errorMessage
    }
}
catch {
    "Oops: $_"
}

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 with the Get-SFTPChildItem cmdlet and reproduce the provided example using -Path '/notExstingPath', -Recurse, and -ErrorAction Stop. Trace how the missing-path error is emitted, then verify that the same command reaches the catch clause rather than only displaying an error.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.