libelektra: highlevel: do not fail without any spec
@haraldg reported a usability problem of the highlevel API.
While it is important that we fail with an inconsistent/wrong spec during kdbOpen it is not a good design choice that elektraGet calls fail because of a missing type in the spec. Let us assume following example program:
#include <stdio.h>
#include <elektra.h>
int main () {
Elektra *elektra = elektraOpen("/sw/test/elektraHighLevel/", NULL, NULL, NULL);
const char *output = elektraGetString(elektra, "output");
printf("%s", output);
return 0;
}
Expected Behavior
It is fine to fail if there is no config nor spec:
kdb rm /sw/test/elektraHighLevel/output
./a.out
# RET: 1
Unwanted Behavior
It is weird to fail if there is no spec and there is a valid value:
kdb set /sw/test/elektraHighLevel/output "Hello World"
./a.out
# RET: 1
Guidelines
In general, we should try to fail within elektraOpen if possible (specs without defaults or value, without types). At run-time we should only fail if there is an unrecoverable error/inconsistency. (e.g. other type specified than asked for, value not according the type and so on…). Not having a spec is neither an error nor an inconsistency.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 18 (14 by maintainers)
Commits related to this issue
- Emphasize that type is required when the HL API is used. Fixes https://github.com/ElektraInitiative/libelektra/issues/3938#issuecomment-903806464 — committed to qwepoizt/libelektra by deleted user 3 years ago
Accidentally closed, my bad. a3d38eb only fixes a small part of this issue.
True, the documentation could be better. At the very least, it should mention the tutorial should be read first.
Yes, the high-level API (without codegen) doesn’t care about
spec:. It needs thetypeon the actual config keys. Thetomlplugin generates atype, so everything works fine.What would be your suggestion how we handle this situation instead? There isn’t really any way of knowing in e.g.
elektraGetLongwhether there is no spec at all, this particular key is missing the spec, or whether justtypeis missing.Should we just say if
typeis missing we try to convert it and if it succeeds it succeeds, if it fails it fails?