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

Author Message
cakruege
[View user's profile]
Donor
Joined: 2015-11-23
Posts: 2
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
Code:


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:
Code:

function Failed
{
   param($e)
   
   $e
}

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


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

Code:

    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?
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24512
Location: Prague, Czechia
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
[View user's profile]
Donor
Joined: 2015-11-23
Posts: 2
prikryl wrote:

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

Thx. You're right.

prikryl 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 Crying or Very sad

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

prikryl wrote:

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


That would be my temporary solution
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24512
Location: Prague, Czechia
OK, I'll consider that.
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License