InvalidFormatException in filename

  1. 2 weeks ago

    Tim S

    Jun 26 Testers Canterbury, UK
    Edited 2 weeks ago

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

    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%%o<FolderItem>si8<FolderItem.PathModes>b
    25 Jun 2020 10:35:48 FATAL: email.imageWrite%%o<email>u8ssssi8f8f8

    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.

  2. Tim P

    Jun 26 Testers, Xojo Pro Rochester, NY
    Edited 2 weeks ago

    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.

  3. Tim S

    Jun 26 Testers Canterbury, UK

    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.

  4. Tim S

    Jun 26 Testers Canterbury, UK
    Edited 2 weeks ago

    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.

  5. Tim P

    Jun 26 Testers, Xojo Pro Rochester, NY

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

  6. Tim S

    Jun 26 Testers Canterbury, UK

    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.

or Sign Up to reply!