FileManager errors do not propagate when debugging target process

Originator:jalkut
Number:rdar://32083596 Date Originated:09-May-2017 04:00 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Version 8.3.2 (8E2002)
Classification:Serious Bug Reproducible:Alwayss
 
Summary:
(NS)FileManager errors that would normally propagate with either an NSError or by throwing in Swift do not propagate the error when running a process in Xcode or via the lldb command line debugger.

Significantly, the expected errors are propagated when the application or tool is run outside a debugging environment.


Steps to Reproduce:
1. Open the attached CopyFailureErrors.xcodeproj
2. Build and run.


Expected Results:
In the console, you should see output reflecting the fact that an error was thrown upon attempting to copy /tmp/file1.txt over /tmp/file2.txt, which has been caused to already exist.


Observed Results:
No error is propagated, leaving the impression that the copy has succeeded when in fact it has not.


Version:
Version 8.3.2 (8E2002)
10.12.4 (16E195)


Notes:



Configuration:


Attachments:

Comments

More: adding unsetenv("OS_ACTIVITY_DT_MODE") to my test app code before the FileManager copy method is invoked causes the bug to disappear.

In my further tests the buggy behavior is exhibited if the OS_ACTIVITY_DT_MODE environment variable is defined when the process is launched.

Example source code for a tool that exhibits the problem as in my project attached to the Radar:

// // main.swift // CopyFailureErrors // // Created by Daniel Jalkut on 5/9/17. // Copyright © 2017 Daniel Jalkut. All rights reserved. //

import Foundation

func doCopyItemTest(_ file1Path: String, _ file2Path: String) { do { // Write something to files 1 and 2 try file1Path.write(toFile: file1Path, atomically: false, encoding: String.Encoding.utf8) try file2Path.write(toFile: file2Path, atomically: false, encoding: String.Encoding.utf8)

    // Now try to copy from file1 to file2
    try FileManager.default.copyItem(atPath: file1Path, toPath: file2Path)
    let file2Contents = try NSString(contentsOfFile: file2Path, encoding: String.Encoding.utf8.rawValue)
    print("FileManager claims success copying file1 to file2, but file2 contents are still \(file2Contents)")
}
catch {
    print("Got error \(error)")
}

}

// Copying over a file yields an error normally let tmpFile1Path = "/tmp/file1.txt" let tmpFile2Path = "/tmp/file2.txt" doCopyItemTest(tmpFile1Path, tmpFile2Path)


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!