BinaryStream.Open ErrorNumber 2 - what is that?

So, I am opening a text file that surely exists and can be read by other apps (e.g. in BBEdit and with the “cat” shell cmd), but Xojo 2016r3 gives me an IOException with ErrorNumber 2 and an empty Message and Reason. Also, when looking at the FolderItem’s properties in the debugger, I see that Exists and IsReadable are true and LastErrorCode is 0. Nothing indicates any potential problem.

And while the LR says that I’d find the Error code meanings on Apple’s website for NSError, that page ( only lists symbols, not any values.

This is quite useless. Nor can I tell what the code means, I cannot even start to guess why I get this exception in the first place.

Any ideas?

Are you sure the file you are trying to access is not opened/locked by any other process while you try to read it?

No, I am not, But regardless, it should be readable. I open it without write permission, after all. And if other apps can open it that way, then it means it’s not exclusively locked, and therefore Xojo should be able to read it, too.

But only if Xojo is NOT asking for exclusive access :wink:

Well, does Xojo do that? It should not. At least not without giving me the option. We’re not even sure that’s the problem here. You add more theories - but do you actually know that’s what Xojo does?

Nope, i don’t know :confused:

Pretty sure error 2 means ‘no such file or directory’
Is the thing you are trying to open an alias?

You say the file is a text file, but you are opening in binary mode rather than textinputstream for some reason.
I seem to recall that other languages use exclusive for binary mode by default. has a locking preference parameter

try opening specifically in ‘Read’ mode

BinaryStream.Open(f, LockModes.Read)

If the above is of no use to you, don’t shout.

That’s Apple’s new design philosophy. Click on a constant and you see its value on the subpage.

I find Apples docs designed this way to be even worse than they were before
Tons of clicks and not much more (I’d say less) actually documented

Looks nice though

I am glad they reduced the font size a bit. I couldn’t believe it when I saw the first version during the Sierra beta phase. I mean, sure, programmers tend to sit much too long in front of their computers, but are their eyes that bad in general?

I usually use Xcode’s docs now. Faster information, less design.

Jeff, it’s a plain text file, and opening a text file as a binary file is definitely not the issue here. Also, as I already wrote, I’m opening it read-only, just like you suggested. Now, how do I figure out what the value 2 means? Clicking on every of those 100s of constants is not a solution. Maybe I should quickly write a web crawler for that Apple web page…


How about using dtruss?

So start your application and get its PID. Then call as ‘root’

dtruss -a -p PID

and open the file in your application. Press Ctrl-C to stop the trace.

Now you can look at the dtruss output for something like

37558/0x1f08e5: 1891341 8 6 open_nocancel("/PATH/TO/YOUR/FILE/THEFILENAME\\0", 0x0, 0x1B6) = -1 Err#13

To get the Error message of the listed no. use “strerror” (see “man strerror” in Terminal).

Quick and dirty I use an Xcode (8) playground

let s2 = NSString(cString: strerror(2), encoding: String.Encoding.utf8.rawValue) let s13 = NSString(cString: strerror(13), encoding: String.Encoding.utf8.rawValue)
which gives “No such file or directory” for Error 2 and in my test “Permission denied” for error 13.
Now you can check for the real error reaon in the system call.

Hope that it helps.

Youre right.
I can’t help you with that , I think that page is poor too.

Mmm… you said [quote]I open it without write permission, after all.[/quote]
To me, that didnt say explicitly ‘I opened it read-only’.
It sounded like it could just be an assumption based on NOT specifically asking for write permission.

Everyone always says ‘show us your code’ :slight_smile:

So Im sure its fine, and I know you’re experienced, but :

What does the opening line of code actually say?
And what is the nativepath of the folderitem you are using , at the point that it you try to open it?

BinaryStream.Open(f, false)

And the second parameter is declared as “readwrite as Boolean”, i.e. it’s opened read-only. Or do you disagree?

Yes, thanks for that. And the examples.

That’s one reason I prefer OSX and Xojo over Linux and digging thru open source C code - Too many cmdline tools that I can’t manage to remember. Even DTrace, as great as it can be, requires me to spend hours on reading up on it again every time before I can use it for a small task.

Well … That assumes that the error codes we get from Xojo’s file functions are using those codes. AFAIK, strerror returns POSIX error codes, whereas Xojo uses MacOS level function calls and therefore gets OSError codes, which are of a different kind.

The issue here is that a single integer is not enough to know how to interpret an error code on OS X and implementing FolderItem can’t be done at one single API level.

POSIX Error:

NO Entity is probably the one.
Reference here: Error Objects, Domains and Codes (Apple developer)

CoreDataErrors.h has the folowing values:

Therefore you should trace via dtruss (which is much easier to use than dtrace). It will show you the underlying OS Error.

Let’s begin with, what framework do you use? Old or new?
What is the “path” you give it, or how do you instantiate the folderitem to that file?

Show some code plz?