Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

highlevel: remove most of error handling from public API #2432

Merged
merged 4 commits into from Feb 25, 2019

Conversation

kodebach
Copy link
Member

@kodebach kodebach commented Feb 20, 2019

As discussed in #2399, this removes most of the current error access functions from the public API.

It also adds border tests for integer types and therefore closes #2430.

@markus2330 please review my pull request

@kodebach
Copy link
Member Author

jenkins build all please

1 similar comment
@kodebach
Copy link
Member Author

jenkins build all please

Copy link
Contributor

@markus2330 markus2330 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! If possible we should avoid having to include kdbprivate.h, otherwise everything looks very fine.

Is the high-level API ready to be released after this PR?

@@ -524,6 +524,7 @@ static ostream & printPrivate (ostream & os, parse_t & p)
<< endl
<< "#include <elektra/types.h>" << endl
<< "#include <elektra/error.h>" << endl
<< "#include <kdbprivate.h>" << endl
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed? It would be good if we can avoid it. If it is only about the enum, we better move the enum within here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's needed for ElektraErrorSeverity, which is used in the generated function elektraErrorLowLevel. The function is used to create the ElektraError struct for low-level errors.

I don't think it is a problem to include kdbprivate.h here. The generated file is elektra/errorsprivate.h and is not intended for external use. It is not even included in any CMake install targets. It is not referenced in any header files, so it basically doesn't exist outside of compiling Elektra.


typedef const char * ElektraKDBErrorGroup;
typedef const char * ElektraKDBErrorModule;

typedef void (*ElektraErrorHandler) (ElektraError * error);

ElektraErrorCode elektraErrorCode (const ElektraError * error);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this also?

@@ -12,6 +12,7 @@

#include <gtest/gtest-elektra.h>
#include <kdbhelper.h>
#include <kdbprivate.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also should have ABI tests, i.e. tests that only use the public interface.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests themselves do only access the public interface. Some use the low-level API too to check the results, but kdbprivate.h is only used for the fatal error handler that outputs error messages. In particular we only use the elektraError* and elektraKDBError* functions that were part of the public interface before this PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For ABI tests it would be needed that no methods of kdbprivate.h is used at all. Otherwise the ABI tests would also fail on changes within kdbprivate.h.


createElektra ();

EXPECT_EQ (elektraGetOctet (elektra, "octet/min"), 0) << "octet/min wrong";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for adding the tests!

@kodebach
Copy link
Member Author

Is the high-level API ready to be released after this PR?

I was thinking, now that we decided to use the specload plugin for code generation, the defaults parameter of elektraOpen causes more problems than it solves. We might want to remove it. But I wouldn't actually remove the parameter. I would just not use it and rename it to config. That way we are prepared, if we need to pass more configuration parameters to elektraOpen in the future (e.g. enabling/disabling certain global plugins, or anything else that has to be done between kdbOpen and kdbGet).

@kodebach
Copy link
Member Author

That way we are prepared, if we need to pass more configuration parameters to elektraOpen in the future

Supporting the notification API through the highlevel API (including code generation) for example would require configuration between kdbOpen and kdbGet. In this case no reasonable defaults exist, unlike with cmd-line options, so configuration has to be user supplied.

We should also probably provide a elektraGetKDB function that returns the KDB handle used by the highlevel API, so that it can be combined with the low-level API more easily. Possibly we also expose the internal KeySet, but I am not sure about that. Although both of these can be added in a future release.

@markus2330
Copy link
Contributor

I was thinking, now that we decided to use the specload plugin for code generation, the defaults parameter of elektraOpen causes more problems than it solves.

The default parameter is still needed because also kdbOpen() or some unrelated part within kdbGet() can fail. The goal would be that the application is always be able to start, independent of KDB.

Supporting the notification API through the highlevel API (including code generation) for example would require configuration between kdbOpen and kdbGet.

You mean for elektraIoSetBinding? I don't think that "configuration" would be an elegant solution, it seems to be more straight-forward to call functions because you need to pass function pointers.

[get internal KDB and KeySet] Although both of these can be added in a future release.

Yes, let us only add it later when it is clear that it will be needed. (e.g. if we decide not to wrap functions like elektraIoSetBinding)

@kodebach
Copy link
Member Author

I don't think that "configuration" would be an elegant solution, it seems to be more straight-forward to call functions because you need to pass function pointers.

Yes, passing any sort of non-string data is very ugly via a KeySet, but I don't see a better solution other than using a custom struct which has to be allocated again. Any configuration before kdbOpen or before kdbGet has to be done by elektraOpen, so the user has to give that information somehow. We also can't delay the kdbGet call until the first elektraGet* because then elektraGet* could fail.

@kodebach
Copy link
Member Author

The default parameter is still needed because also kdbOpen() or some unrelated part within kdbGet() can fail. The goal would be that the application is always be able to start, independent of KDB.

Currently elektraOpen always returns NULL if kdbOpen or kdbGet fails.

@markus2330
Copy link
Contributor

Yes, for severe problems elektraOpen is allowed to fail. But for a later elektraGet also kdbGet (or even kdbOpen in case of new mountpoints) might fail. But then we should continue to run, as we do not want to fail during run-time.

@kodebach
Copy link
Member Author

jenkins build all please

1 similar comment
@kodebach
Copy link
Member Author

jenkins build all please

@kodebach
Copy link
Member Author

Contrary to what github thinks, all build jobs where successful. One of the Cirrus CI jobs is listed twice, clicking on Details and viewing on Cirrus CI reveals that the job finished.

@markus2330 markus2330 merged commit 90ab22e into ElektraInitiative:master Feb 25, 2019
@markus2330
Copy link
Contributor

Thank you for the great work!

@kodebach kodebach deleted the elektra_api branch June 13, 2019 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Highlevel API tests
2 participants