Recent

Author Topic: How to convert all values of ioresult() into text messages?  (Read 8692 times)

Thaddy

  • Hero Member
  • *****
  • Posts: 16945
  • Ceterum censeo Trump esse delendam
Re: How to convert all values of ioresult() into text messages?
« Reply #15 on: September 30, 2019, 09:36:35 pm »
The original error codes are the ones from the official documentation. Anything else is custom as per my examples.
That also means that e.g. 80 is not a reliable entry, because it is custom. You can not rely on any codes beyond the official ones to be valid all the time.
They may mean different things in different programs.
The official documentation is as per my links. (The wiki does not count, but I will write an entry or an updated entry)

The IOResult mechanism predates exception handling (part of Pascal since the 70's).
You can use it instead of manually raising exceptions with raise

Good example: http://turbopascal.org/file-operations declarations http://turbopascal.org/system-unit
« Last Edit: September 30, 2019, 10:02:02 pm by Thaddy »
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

Hartmut

  • Hero Member
  • *****
  • Posts: 905
Re: How to convert all values of ioresult() into text messages?
« Reply #16 on: September 30, 2019, 09:44:30 pm »
I'm looking for a function which converts the values of function system.ioresult() into text messages on Windows and Linux. I didn't find one.
From the responses you got above, my guess is there is no complete, up to date, list of IoResult values around you could use to produce such a function.

If that is correct (and it seems to be), doing a text search (grep or equivalent) in the compiler sources for the identifier "InOutRes" reveals the locations and values assigned to that variable which is what is returned by IoResult (using the word pointer HInOutRes.)

IOW, with a reasonable effort you can make an accurate list of  values returned by IoResult per O/S.

Note that for some OSs (maybe all, I don't know) there seem to be places where InOutRes is assigned whatever value is held in the variable errno.  In those cases you'll have to determine the possible values of errno.

HTH.

Hello 440bx, that sounds like a very interesting idea. I searched the sources for IoResult and HInOutRes and got nearly 700 matches, most of them assignments, many setting zero. Tomorrow I will inspect the results more closely and see, if I can find more error codes. But it could be difficult to detect the meaning of a "new" error code. And, as you said, at some places a variable value like 'errno' is set. There I see only a minimal chance to detect, which values are possible (and their meanings). Thanks for your help.

440bx

  • Hero Member
  • *****
  • Posts: 5302
Re: How to convert all values of ioresult() into text messages?
« Reply #17 on: September 30, 2019, 10:07:15 pm »
I searched the sources for IoResult and HInOutRes and got nearly 700 matches, most of them assignments, many setting zero.
From the cursory searches I did, it seems sufficient (for a first pass) to just search for "inoutres".  Searches for IoResult and HInOutRes didn't produce much "useful/interesting" information.

Just FYI, I am using Windows and a text search utility called "FileLocator" (free download - lite version), which I find very usable and capable.  Using that utility, it reported 110 files where "inoutres" is accessed.  From the list of files, it is readily visible which O/S the matches are for.    Confining the searches to the O/Ss you are interested in, would likely significantly reduce the number of matches.

But it could be difficult to detect the meaning of a "new" error code.
If "new" is arbitrarily defined as "not present in the documentation" then, it shouldn't be too difficult.

And, as you said, at some places a variable value like 'errno' is set. There I see only a minimal chance to detect, which values are possible (and their meanings).
That definitely has the potential to be a problem.  Only way to know is to dig into it.  With some luck, either the number of instances where errno is used is small or they can be easily grouped and processed.

Thanks for your help.
You're welcome.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v4.0rc3) on Windows 7 SP1 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 16945
  • Ceterum censeo Trump esse delendam
Re: How to convert all values of ioresult() into text messages?
« Reply #18 on: September 30, 2019, 10:31:30 pm »
@440bx
Errno is used as a parameter name. It is not a variable in system. errorcode(writeable const) and InOutRes are.
You still can't rely on that to be the ultimate truth: it also may conflict on a per program basis.
For OS related error codes you can set InOutRes with https://www.freepascal.org/docs-html/rtl/sysutils/getlastoserror.html
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

440bx

  • Hero Member
  • *****
  • Posts: 5302
Re: How to convert all values of ioresult() into text messages?
« Reply #19 on: September 30, 2019, 10:43:54 pm »
@440bx
Errno is used as a parameter name. It is not a variable in system. errorcode(writeable const) and InOutRes are.
You still can't rely on that to be the ultimate truth: it also may conflict on a per program basis.
For OS related error codes you can set InOutRes with https://www.freepascal.org/docs-html/rtl/sysutils/getlastoserror.html
No doubt, the results of the search(es) have to be filtered and analyzed.  A rather cursory "analysis" of that route seemed to at least merit a try.  I have no doubt that producing a complete and accurate list will likely require some work that is not immediately obvious.

(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v4.0rc3) on Windows 7 SP1 64bit.

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: How to convert all values of ioresult() into text messages?
« Reply #20 on: October 01, 2019, 01:42:27 am »
Hi Hartmut & 440bx

I found a fpc Mac-Source with ioerror constants:

https://github.com/graemeg/freepascal/blob/master/rtl/macos/macostp.inc

It contains also error 18 mentioned by Hartmut:
Code: Pascal  [Select][+][-]
  1.  
  2. Sys_EXDEV       = 18;   { Cross-device link }

Look at line 1344 ff - just before the EOF.

Winni

jamie

  • Hero Member
  • *****
  • Posts: 6892
Re: How to convert all values of ioresult() into text messages?
« Reply #21 on: October 01, 2019, 02:11:49 am »
Windows has "FormatMessage" with that, you can pass the error code to it and it will generate a string with the verbose of that message from predefined message tables in the OS.
The only true wisdom is knowing you know nothing

440bx

  • Hero Member
  • *****
  • Posts: 5302
Re: How to convert all values of ioresult() into text messages?
« Reply #22 on: October 01, 2019, 02:54:41 am »
Windows has "FormatMessage" with that, you can pass the error code to it and it will generate a string with the verbose of that message from predefined message tables in the OS.
True but, those have only an occasional (actually somewhat rare) correspondence with the values returned by IoResult, e.g, IoResult 100 (d) is "Disk Read Error" whereas Window's LastError 100 (d) is "Cannot create another system semaphore".

(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v4.0rc3) on Windows 7 SP1 64bit.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5968
  • Compiler Developer
Re: How to convert all values of ioresult() into text messages?
« Reply #23 on: October 01, 2019, 09:10:51 am »
Windows has "FormatMessage" with that, you can pass the error code to it and it will generate a string with the verbose of that message from predefined message tables in the OS.
FormatMessage is for error codes returned by the operating systems (e.g. GetLastOSError). InOutRes however is for Pascal only error codes and it's tried to map operating system errors to the known codes.

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: How to convert all values of ioresult() into text messages?
« Reply #24 on: October 01, 2019, 06:02:33 pm »
Hi!

I found a big list of Windows API errors provided by some Delphi fans. It contains a lot of I/O errors and some other errors, but it is much more complete than the fpc doc page. It also contains ioerror 32 that I mentioned.

http://delphi-techie.faithweb.com/rich_text_4.html

Hope it helps!

Winni

Hartmut

  • Hero Member
  • *****
  • Posts: 905
Re: How to convert all values of ioresult() into text messages?
« Reply #25 on: October 01, 2019, 07:31:50 pm »
I followed the idea from 440bx and searched the complete FPC 3.0.4 sources for "InOutRes" (679 matches) and "HInOutRes" (18 matches). First I only looked at matches, where a constant value is assigned. Here is my yield:

 - error 1 occurs on many OS (amicommon, atari, MacOS, netware, netwlibc) and means something like "Function not supported"
 - error 8 occurs on atari for 'errno' of -37 and -39 (meaning unknown) in fpc\3.0.4\source\rtl\atari\system.pp lines 133+134
 - error 9 occurs on atari for 'errno' of -40 (meaning unknown) in fpc\3.0.4\source\rtl\atari\system.pp line 135
 - error 18 occurs on amicommon and means "ERROR_NO_MORE_ENTRIES" (probably FindFirst/FindNext) in fpc\3.0.4\source\rtl\amicommon\sysos.inc line 79 which gives a meaning conflict to error 18 in reply #3
 - error 20 occurs on MacOS when you pass a file instead of a directory to rmdir() and means "Not a directory" in fpc\3.0.4\source\rtl\macos\sysdir.inc line 57
 - error 217 occurs on many OS (aix, beos, bsd, haiku, MacOS, Nintendo, netware, netwlibc, solaris) when the OS returns ESysENOMEM/Sys_ENOMEM or ESysEFAULT/Sys_EFAULT. The 1st means "Not enough Memory", the 2nd means on MacOS "Illegal filename", other OS write "Bad address". I wonder why they all are put together to 217, because they are very different. I found no common meaning for them. It makes no sense to return an error code where the meaning is not clear :-(

I spent a couple of hours to create that list and I'm not satisfied because I dont't have a (clear) meaning for errors 8, 9 and 217. Beside this there are about 70 matches, where InOutRes is assigned a value from a variable. For me it's to hard to dive more deaper.

I will create a message function with the error codes I got so far. And in the case, that I stumble in the future across an unknown error code, I will investigate that then.

If someone has informations about above error codes 8, 9, 217 (or others) please write it here.

Thanks a lot to all who helped me.
« Last Edit: October 01, 2019, 07:33:34 pm by Hartmut »

Hartmut

  • Hero Member
  • *****
  • Posts: 905
Re: How to convert all values of ioresult() into text messages?
« Reply #26 on: October 01, 2019, 07:38:57 pm »
I found a big list of Windows API errors provided by some Delphi fans. It contains a lot of I/O errors and some other errors, but it is much more complete than the fpc doc page. It also contains ioerror 32 that I mentioned.

http://delphi-techie.faithweb.com/rich_text_4.html

Thank you very much for that link. Unfortunately it does not contain error code 217. But I have added this link to my list of explanations for error codes.

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: How to convert all values of ioresult() into text messages?
« Reply #27 on: October 01, 2019, 07:52:59 pm »
Hi!

Error 18 is indeed the result of findfirst/findnext if there are no more files. I don't know about Linux, but that is the Windows default result, like it is in Delphi.

What also might be interresting for you are the old DOS Errors, which are partly obsolete (Attempt to write on a write-protected diskette), but might give a solution for 8 and 9:

DosError 08  Insufficient memory
DosError 09  Invalid memory block address

The DosErrors you can find here:

http://stanislavs.org/helppc/dos_error_codes.html

Winni

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: How to convert all values of ioresult() into text messages?
« Reply #28 on: October 01, 2019, 08:03:06 pm »
Hi!

I found a Delphi page about the "mystery" error 217: It is used after a fatal error when no exeption could be raised:

In fact, Delphi executables will die with runtime error 217 when an exception was raised before SysUtils is initialized or after it is finalized. In both situations the regular exception handling is not put in place. 

From https://www.delphipraxis.net/4845-runtime-error-217-a.html

Winni

Hartmut

  • Hero Member
  • *****
  • Posts: 905
Re: How to convert all values of ioresult() into text messages?
« Reply #29 on: October 01, 2019, 08:43:13 pm »
Error 18 is indeed the result of findfirst/findnext if there are no more files.
Yes, I know, but I have seen this code never coming from function IOresult(). Only coming from functions findfirst/findnext or old variable DosError.

... but might give a solution for 8 and 9:
DosError 08  Insufficient memory
DosError 09  Invalid memory block address
Yes, I also suspected that, but I hesitate to show this messages without being sure, that Atari uses DOS codes at his place.

I found a Delphi page about the "mystery" error 217: It is used after a fatal error when no exeption could be raised:
In fact, Delphi executables will die with runtime error 217 when an exception was raised before SysUtils is initialized or after it is finalized. In both situations the regular exception handling is not put in place. 

Hmm. Can you imagine by this explanation some pascal code where IOresult() returns 217? For me there is a difference between IOresult() and aborting a program with runtime error 217 ...

Thanks for your help and the new links.

 

TinyPortal © 2005-2018