[m-rev.] IO error type
Julien Fischer
jfischer at opturion.com
Thu Aug 18 19:09:12 AEST 2022
On Thu, 18 Aug 2022, Peter Wang wrote:
>> 5. We also add the functions you listed below
>>
>>>>> :- pred get_error_name(io.error::in, string::out)
>>>>> is semidet.
>>>>>
>>>>> % As above, but takes a system_error instead.
>>>>> %
>>>>> :- pred get_system_error_name(system_error::in, string::out)
>>>>> is semidet.
>>
>> except that the signature of the latter one would be:
>>
>> :- pred get_system_error_name(io.error::in, string::out)
>> is semidet.
>
> Right, if a system_error could be value from multiple sets of errors
> then we can't have a predicate that converts an system_error (only) to a
> string.
>
>> (I hope there's a way of getting Windows error code name, that doesn't
>> involve switching over all 5000 or so Windows error codes; perhaps
>> FormatMessage can do that?)
>>
>
> I couldn't find one :(
Neither could I.
> The MinGW-w64 winerror.h defines ~1765 ERROR_* constants, which should
> be far beyond what we need to recognise (practically).
At the moment the only ones we generate are those in the dir module.
I think it would suffice to handle those plus the most common other
cases and for every other value construct a string of the form:
"System error: 0xNNNNNNN"
(That's no worse than what Microsoft does in various places; the number
is hexadecimal since that what Microsoft's documentation does.)
> Both the switch for the POSIX and Windows errors would be
> auto-generated, so it's just a matter of code size.
For "unrecognised" errno values, I suggest we create a string
of the form:
"errno: NNNNN"
(In decimal this time.)
Julien.
More information about the reviews
mailing list