OS APIs without error codes

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
rdos
Member
Member
Posts: 3297
Joined: Wed Oct 01, 2008 1:55 pm

Re: OS APIs without error codes

Post by rdos »

Solar is on my ignore-list unless he writes something really interesting. Above post ignored...
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: OS APIs without error codes

Post by Solar »

Doesn't make much difference, when you're blithely ignoring the "interesting" parts just as well, huh?

Anyway, that post was not for your benefit.
Every good solution is obvious once you've found it.
rdos
Member
Member
Posts: 3297
Joined: Wed Oct 01, 2008 1:55 pm

Re: OS APIs without error codes

Post by rdos »

[off topic]
Since Solar changed his post, I feel I need to answer on this one (not because it is interesting, but because it spreads misinformation)
Solar wrote:You didn't "add choices". You made a claim, we shot it down, and you're now trying to weazel out of it.
Correction: Lots of people didn't understand the concept, and posted incorrect code, yourself included. You cannot "shoot" something down unless you understand it. :roll:
[/off topic]
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: OS APIs without error codes

Post by Solar »

*Sigh*

Everybody here does understand your concept. Nobody here - with the noteable exception of your person - thinks that it's a good idea. And because you have a personality deficit that makes you incapable of ever admitting that you've been chasing wild geese, and rather think that you're the genius and everybody else is wrong you're trying to spin it off into a discussion about who ever could write the more convoluted source example.

I'm not playing that game anymore.

You know the story about the motorist listening to the traffic announcement about "a person driving against the traffic"?

"One? There are hundreds of them!"

That motorist is you. All I am still doing here is trying to keep others from following your example. End of communication.
Every good solution is obvious once you've found it.
User avatar
Griwes
Member
Member
Posts: 374
Joined: Sat Jul 30, 2011 10:07 am
Libera.chat IRC: Griwes
Location: Wrocław/Racibórz, Poland
Contact:

Re: OS APIs without error codes

Post by Griwes »

My last post in this topic. When you return boolean status, you are doing less than returning error code. Even using error code oriented API, you can just compare the error code to OK value and proceed as with your boolean flag oriented API.
Reaver Project :: Repository :: Ohloh project page
<klange> This is a horror story about what happens when you need a hammer and all you have is the skulls of the damned.
<drake1> as long as the lock is read and modified by atomic operations
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re: OS APIs without error codes

Post by bubach »

i'm having a problem with the part where returning an error code turns into a error pop-up for the user...

there is NO reason the error codes can't just be discarded, and carry on just like there wasn't any. but if I wanted to use it, it should be there - as an option to the programmer.
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

Re: OS APIs without error codes

Post by qw »

A little contribution to the discussion: an alternative to error codes are exceptions, but that's probably a lot less efficient.
rdos
Member
Member
Posts: 3297
Joined: Wed Oct 01, 2008 1:55 pm

Re: OS APIs without error codes

Post by rdos »

Griwes wrote:My last post in this topic. When you return boolean status, you are doing less than returning error code. Even using error code oriented API, you can just compare the error code to OK value and proceed as with your boolean flag oriented API.
That is true, but if you use the API in that way, why bother with returning the error code in the API when nothing uses it?

The only other valid reason I can come up with for keeping the error codes, if you don't use them, is POSIX compliance. OTOH, a possible remedy would be to return the most likely error code to POSIX.
User avatar
AndrewAPrice
Member
Member
Posts: 2300
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Re: OS APIs without error codes

Post by AndrewAPrice »

I agree with what the original poster is trying to accomplish - to remove the need to check errors after every call.

Errors are errors, they should occur outside of the norm, and you shouldn't have to do:

Code: Select all

int pid = sys_getPid();
if(sys_error() != 0)
{
}

fork();
if(sys_error() != 0)
{
}

etc.. etc..
It just makes code messy and ugly. You could use an exception based approach - that is register allow a program to optionally register an error callback function, then if an error code is generated in the kernel, make the user thread call the error callback function if one is registered.

Then inside the error callback function, the programmer can choose what to do (check the error messages and either ignore it or throw the relevant exception if the language supports it).
My OS is Perception.
User avatar
iansjack
Member
Member
Posts: 4703
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: OS APIs without error codes

Post by iansjack »

rdos wrote:That is true, but if you use the API in that way, why bother with returning the error code in the API when nothing uses it?
If you are the only person who ever writes application programs for your OS, then you might have a point. But if you expect other people to program for it then some might choose to use the error code as just a Boolean flag whist others might choose to use it to handle the error. Even a single programmer might sometimes want a simple failure indication but at other times might want to process the failure.

So, if you have a half-arsed OS that only you will ever use, then you are correct. But most people writing an OS will want to include just a little flexibility in it to suit different programmers.
rdos
Member
Member
Posts: 3297
Joined: Wed Oct 01, 2008 1:55 pm

Re: OS APIs without error codes

Post by rdos »

iansjack wrote:If you are the only person who ever writes application programs for your OS, then you might have a point. But if you expect other people to program for it then some might choose to use the error code as just a Boolean flag whist others might choose to use it to handle the error. Even a single programmer might sometimes want a simple failure indication but at other times might want to process the failure.

So, if you have a half-arsed OS that only you will ever use, then you are correct. But most people writing an OS will want to include just a little flexibility in it to suit different programmers.
Well, I find it likely that I would be the only major player that will write applications for my OS, but I might be wrong.

Anyway, an error-code less API also means that you optimize the API to have functions that are well defined and have well-defined error causes. This is done in multiple ways, like not allowing structures to be passed to kernel, and not overloading file operations with multiple unrelated things like sockets and pipes. In fact, functions that typically have multiple possible error returns must be implemented in an user level library, and then anybody is free to use a class-based interface, or a more traditional C/error-code based one. Even file handle sharing among processes must be implemented in clib, since RDOS has no way to open or redirect a file handle to console input, and does not support inheriting handles in a child process. The file API can only be used with files in the current process. Therefore, at the C-lib level, the classical error codes in the file-IO and stream interface are supported, they are just not supported when the raw file API is used. So for file-IO, users already have a choice. Use the standard C library functions.
User avatar
gravaera
Member
Member
Posts: 737
Joined: Tue Jun 02, 2009 4:35 pm
Location: Supporting the cause: Use \tabs to indent code. NOT \x20 spaces.

Re: OS APIs without error codes

Post by gravaera »

rdos wrote: When I worked a lot on the Windows API, ... I'd wish I could have traced the syscall into kernel to see why it failed.
K, so you want to propose that kernels allow you to hook into them with state dumps or status checking functions? No problem -- this can easily be implemented alongside a conventional error-code returning API in your kernel. There's still no need to try to debunk error code return values :|
17:56 < sortie> Paging is called paging because you need to draw it on pages in your notebook to succeed at it.
User avatar
iansjack
Member
Member
Posts: 4703
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: OS APIs without error codes

Post by iansjack »

rdos wrote:Well, I find it likely that I would be the only major player that will write applications for my OS, but I might be wrong.
OK, I appreciate where you are coming from (and I don't think you are wrong).

As you are the only person who will ever use or program your OS you are, of course, free to make whatever design decisions you like (however poor I may think they are). But I don't understand why we are wasting our time discussing something that is of no importance to all but one of us.

I'm out of here.
User avatar
Yoda
Member
Member
Posts: 255
Joined: Tue Mar 09, 2010 8:57 am
Location: Moscow, Russia

Re: OS APIs without error codes

Post by Yoda »

Solar wrote:All I am still doing here is trying to keep others from following your example. End of communication.
The things are so obvious, that I even didn't want to enter the discussion. I can only wonder why it is not obvious for rdos. So there is no need for keeping others from this design error.
1. That two approaches are logically almost equivalent. The primary difference is that emulation of error codes is less efficient since it requires a call to kernel for each query instead of a simple comparison or even a table lookup.
2. "Almost" in the previous statement means that in query design the situation may change (while the thread is thinking what's happened) and chasing the changing situation may make the program slightly crazy. In error codes design this situation is excluded.
3. Nothing prevents the parallel implementation of both designs for that "originally thinking" programmers. But i'd prefer not to have that query mechanism at all, cause it may tempt a programmer to use ineffective code.
Yet Other Developer of Architecture.
OS Boot Tools.
Russian national OSDev forum.
User avatar
Griwes
Member
Member
Posts: 374
Joined: Sat Jul 30, 2011 10:07 am
Libera.chat IRC: Griwes
Location: Wrocław/Racibórz, Poland
Contact:

Re: OS APIs without error codes

Post by Griwes »

rdos wrote:
Griwes wrote:My last post in this topic. When you return boolean status, you are doing less than returning error code. Even using error code oriented API, you can just compare the error code to OK value and proceed as with your boolean flag oriented API.
That is true, but if you use the API in that way, why bother with returning the error code in the API when nothing uses it?

The only other valid reason I can come up with for keeping the error codes, if you don't use them, is POSIX compliance. OTOH, a possible remedy would be to return the most likely error code to POSIX.
No, POSIX is sh*t, generally. There is exactly one word, which's meaning you fail to understand, and that word has already been mentioned: "flexibility".

And in the start you generalized. The topic wasn't "I'm thinking about implementing API without error codes in my OS that no-one will ever write programs for", but you've implied that "error-codeless APIs are better in every possible case". Here, again: check the definition of word "flexible". And, more important: don't imply that solutions that work for RDOS will always work and are far superior - because you are just wrong. And yes, you are implying that they are superior, you do it in every thread lately.
Reaver Project :: Repository :: Ohloh project page
<klange> This is a horror story about what happens when you need a hammer and all you have is the skulls of the damned.
<drake1> as long as the lock is read and modified by atomic operations
Locked