Exception calling "Resolve" with "2" argument(s): "File not found"

Advertisement

NottaSmartMan
Joined:
Posts:
43

Exception calling "Resolve" with "2" argument(s): "File not found"

I'm using some code based on the "Synchronization" PowerShell code found here:
Automating transfers or synchronization in parallel connections over SFTP/FTP protocol

The code works perfectly under most situations. However, I'm having one issue. If the file is open/locked/in-use, the thread will skip/continue as expected, but then return an error and crash/abort/exit.

Any ideas?
I believe this is the relevant section of code from the logs, but I'll can attach them if need be.
< 2024-12-05 18:12:06.315 The process cannot access the file because it is being used by another process
. 2024-12-05 18:12:06.323 Answer: Skip
* 2024-12-05 18:12:06.323 (ESkipFile) Can't open file 'C:\Users\<redeacted>\test\New Microsoft Excel Worksheet.xlsx'.
* 2024-12-05 18:12:06.323 System Error.  Code: 32.
* 2024-12-05 18:12:06.323 The process cannot access the file because it is being used by another process
. 2024-12-05 18:12:06.323 Copying finished: Transferred: 0, Elapsed: 0:00:00, CPS: 0/s
. 2024-12-05 18:12:06.323 Session upkeep
. 2024-12-05 18:12:06.323 Looking for network events
. 2024-12-05 18:12:06.323 Timeout waiting for network events
(ESkipFile) [1] Script Aborted Abnormally.
(ESkipFile) [1] $difference.Resolve($syncSession, $transferOptions) # | Out-Null.
> 2024-12-05 18:12:06.439 Script: exit
Additional data:
  Additional Error Info:                                                                                           
    Error command   : $difference.Resolve($syncSession, $transferOptions) # | Out-Null                                  
    Error message   : Exception calling "Resolve" with "2" argument(s): "File not found"
* The | Out-Null isn't normally commented out, but it was for this debugging session in hopes of giving me more info to track down what's going on.

I *think* I may have found a workaround by wrapping the Resolve method in a try/catch loop, but would like to know if that more of a lame hack and if I'm just hiding the root cause that going to really bite me later. Suggestions?

Here's what I'm doing to try and get around the issue:
try {
  $difference.Resolve($syncSession, $transferOptions) | Out-Null    
}
catch {
}

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,541
Location:
Prague, Czechia

Re: Exception calling "Resolve" with "2" argument(s): "File not found"

I assume you are using Session.QueryReceived to ignore the errors, right?
The behaviour you are seeing is expected.
With the current API it's indeed hard to distinguish fatal errors (like losing connection) from single-operation errors. I'll think about it.

Reply with quote

NottaSmartMan
Joined:
Posts:
43

Correct, I'm using Session.QueryReceived to ignore the error. It works for other situations such as when the script is unable to update the timestamp, but fails hard when the file is locked/open.

Does my Try/Catch workaround seem valid, or do I run the risk of larger issues such as skipping over additional file/folders that were intended to be handled by the errored thread?

If you find a proper fix, I'd love to test it.

Reply with quote

Advertisement

You can post new topics in this forum