InvalidFormatException in filename

A user is reporting to me that he gets an InvalidFormatException. The stack trace looks like this:

[quote]25 Jun 2020 10:35:48 FATAL: Error - fatal exception ‘UnsupportedFormatException’, number 0
25 Jun 2020 10:35:48 FATAL: Reason: The path passed into new FolderItem was invalid
25 Jun 2020 10:35:48 FATAL: Message: The path passed into new FolderItem was invalid
25 Jun 2020 10:35:48 FATAL: Stack: RuntimeRaiseException
25 Jun 2020 10:35:48 FATAL: _Z27RaiseExceptionClassWMessageRK13ClassDeclBase6stringl
25 Jun 2020 10:35:48 FATAL: FolderItemPathModeAndAliasCtor
25 Jun 2020 10:35:48 FATAL: FolderItem.Constructor%%osi8<FolderItem.PathModes>b
25 Jun 2020 10:35:48 FATAL: email.imageWrite%%ou8ssssi8f8f8
[/quote]

which tells me it’s in my imageWrite method. Further, there’s only one “new FolderItem” in the method, which looks like this:

Var s as String, f as FolderItem s = "/path/to/some/myfile" f = new FolderItem (s, FolderItem.PathModes.Native)

So I’m concluding that some part of s must contain invalid characters, an idea which is supported by the doc for InvalidFormatException. But what characters are invalid? I’ve tested with a non-existent path, but the FolderItem is created OK, so it can’t be that (what happens with a non-existent path is an IOException if I try to create the file).

It’s not slash (/) or colon (:), as I already filter those out. So what characters can generate an InvalidFormatException? StackExchange doesn’t appear to think any character is invalid.

User’s doing this under macOS.

InvalidFormatException doesn’t mean the characters are invalid. Reading the message the exception gave you,

25 Jun 2020 10:35:48 FATAL: Error - fatal exception 'UnsupportedFormatException', number 0 25 Jun 2020 10:35:48 FATAL: Reason: The path passed into new FolderItem was invalid 25 Jun 2020 10:35:48 FATAL: Message: The path passed into new FolderItem was invalid
we can tell The path passed into new FolderItem was invalid. It’s not just a specific character, there’s something wrong with the path. On macOS, it could be permissions, you don’t always have access to anywhere you want because of sandboxing or translocation.

Wrap the new FolderItem in a Try...Catch for the InvalidFormatException to handle it.

OK, thanks. In fact I just did some testing and FolderItem was OK if I gave it a string with no TextEncoding, and with invalid UTF-8 and no TextEncoding.

I’ve made a new verson with a Try/Catch and some extra logging so I’ll see just where my friend (huh!) is trying to write to. Once I can see that I can figure out some better bulletproofing.

Hmmm, so far I still can’t reproduce the problem. I removed all permissions from a folder on my Desktop (chmod guo-rwx foldername), and yet “new FolderItem” is quite happy to create a folder item for something within it.

I think finding out what path your friend’s machine is trying to use will be a very helpful piece to the puzzle.

I just discovered that if I replace one of the characters in the filename with a NUL (&h00) then it provokes the exact error that was reported. Other low-end ASCII values are OK. This won’t show up in the extra logging I was mentioning, unfortunately.