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

Most upvoted comments

Accidentally closed, my bad. a3d38eb only fixes a small part of this issue.

It is not so clearly said in […]

True, the documentation could be better. At the very least, it should mention the tutorial should be read first.

It seems to work without type set in spec: (see what I wrote in the second message)

Yes, the high-level API (without codegen) doesn’t care about spec:. It needs the type on the actual config keys. The toml plugin generates a type, 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. elektraGetLong whether there is no spec at all, this particular key is missing the spec, or whether just type is missing.

Should we just say if type is missing we try to convert it and if it succeeds it succeeds, if it fails it fails?