[m-users.] Checking io.error programmatically

Peter Wang novalazy at gmail.com
Thu Mar 21 17:47:57 AEDT 2019


On Wed, 20 Mar 2019 09:26:59 -0500, Charles Shuller <charles.shuller at gmail.com> wrote:
> Hello,
> 
> Is there a way to check io.error programmatically?

No.

> 
> I see a number of functions which return it, but it's type definition isn't
> published and the docs just say:  Use io.error_message to decode it.
> 
> This returns a, presumably localized, string for an end user.

It shouldn't actually be localized unless you call setlocale(), I think.
Nonetheless, the error message would be platform-dependant so not
something you want to depend on.

> 
> My specific use case is to test if a file exists at all, and take different
> action based on it's existence.   I can manage that with io.call_system,
> but this isn't exactly portable, and seems a bit messy.

io.file_type is the closest thing in the standard library so far.
Unfortunately it doesn't distinguish ENOENT from other errors.
We should probably add a new predicate that can report ENOENT back.
Until then, you can use a foreign_proc to call stat/lstat.

Peter


More information about the users mailing list