Error Domain=NSCocoaErrorDomain Code=257 "The file couldn’t be opened because you don’t have permission to view it"

Hi! I am facing this strange error in my computer.

I first happen to see this on some CXTest while running some snapshot tests and all files that where not created by me couldn't be opened.

I tested it on a playground and keeps failing to get de contents of the file using the Data method. I did it just to check if the problem was on the project configurations but the problem remains.

My playground is just:

import Foundation

let fileUrl = URL(fileURLWithPath: "MYPATH", isDirectory: false)

let data = try Data(contentsOf: fileUrl)

The path is correct, the file exists and thorws:

Playground execution terminated: An error was thrown and was not caught:
Error Domain=NSCocoaErrorDomain Code=257 "The file “file.png” couldn’t be opened because you don’t have permission to view it." UserInfo={NSFilePath=MYPATH.png, NSUnderlyingError=0x600000536700 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}```

I run ls -la over the files that are being opened and those that aren't, but the permissions over all files are the same. I do not know what could be causing this error. And my coworkers do not face this error.

I am working with xcode 14.1 and MacOS Monterrey 12.6.1 , and earlier I had the same problem with XCode 13.

I appreciate any help. Thanks!

Just because the path is correct doesn't mean you have permission to access it.

Well.. by deleting everything and re-snapshot everythig. Works! But no one will approve my 3k changes on github... yay!

Error Domain=NSCocoaErrorDomain Code=257 "The file couldn’t be opened because you don’t have permission to view it"
 
 
Q