Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

martin

Re: How to catch errors correctly? server unreachable, fingerprint wrong, access denied, etc.

OK, I'll consider that.
cakruege

Re: How to catch errors correctly? server unreachable, fingerprint wrong, access denied, etc.

martin wrote:


Indeed the mere $e expression does not yield any output.

Thx. You're right.

martin wrote:


Anyway, it's the same information as you get from the exception, so it won't help.

Hmm, that's not what I wanted to hear :cry:

I'd like to suggest a new feature:
For example new exceptions types that inherit from SessionRemoteException
HostNotFoundException
WrongFingerprint
AccessDenied

or new Failure2-Event with proper states

martin wrote:


The best you can do is to parse Exception message (not log).


That would be my temporary solution
martin

Re: How to catch errors correctly? server unreachable, fingerprint wrong, access denied, etc.

The Session.Failed is called all these scenarios.

Indeed the mere $e expression does not yield any output. I do not know why, I do not know PowerShell good enough. But Write-Host $e does.
Anyway, it's the same information as you get from the exception, so it won't help.

The best you can do is to parse Exception message (not log).
cakruege

How to catch errors correctly? server unreachable, fingerprint wrong, access denied, etc.

Hi,

I'm using this powershell code example:
library_powershell#module

I'm trying to differentiate between errors.
For example:
-host unreachable
-fingerprint wrong
-access denied

I replaced Exception with WinSCP.SessionRemoteException
catch [WinSCP.SessionRemoteException]

{
   Write-Host "WinSCP.SessionRemoteException"
    Write-Host $_.Exception.Message
    exit 1
}

but every of these 3 failures is a WinSCP.SessionRemoteException. -> didn't help

add failed handler:
function Failed

{
   param($e)
   
   $e
}

$session.add_Failed( { Failed($_) } )


Failed method didn't get called for every of these 3 failures -> didn't help

    finally

    {
        # Disconnect, clean up
        $session.output
        $session.Dispose()
    }

Session.output has the correct information but it's bad parseable text.
Sometimes it is the last line, sometimes not.

What do I do wrong?