If a certificate, private key or bundle can not be loaded from the file system, we get an IOError with a description that looks like this:
fopen(file:mode:): No such file or directory (errno: 2)
It would be nice if the error description would also include the file path of the file that could not be found.
Modifications
change fopen file argument from UnsafePointer<CChar> to String. All existing call sites already have a String. If we want to include the file path in the error description we also want it as a String. We could convert UnsafePointer<CChar> to a String through String(cString:) but to reduce allocations to a minimum we can also just pass in a String directly.
same as above for mode
include the file path in the reason string of all IOErrors thrown by Posix.fopen
Result
Better error description:
fopen(file: "/nonexistent/path", mode: "rb"): No such file or directory (errno: 2)
Motivation
If a certificate, private key or bundle can not be loaded from the file system, we get an IOError with a description that looks like this:
It would be nice if the error description would also include the file path of the file that could not be found.
Modifications
fopen
file argument fromUnsafePointer<CChar>
toString
. All existing call sites already have aString
. If we want to include the file path in the error description we also want it as a String. We could convertUnsafePointer<CChar>
to aString
throughString(cString:)
but to reduce allocations to a minimum we can also just pass in aString
directly.mode
reason
string of allIOError
s thrown byPosix.fopen
Result
Better error description: