Skip to content

Warn / Error on bad schema #16

@d70-t

Description

@d70-t

Is your feature request related to a problem? Please describe.

I tried building a custom schema (and custom message types, but that's irrelevant here) for FDB. I came up with a schema similar to:

[a[b?[c]]]
[a[b[d]]]

I.e. if c is present in the key, b is optional, but if d is present, b is required. I expected this to work, however the following sampe code fails:

#include <fdb5/api/FDB.h>
#include <eckit/runtime/Main.h>

int main(int argc, char** argv) {
    eckit::Main::initialise(argc, argv);
    auto fdb = fdb5::FDB{};
    fdb.archive(fdb5::Key({{"a", "1"}, {"b", "2"}, {"c", "4"}}), "foo", 4);  // works fine
    fdb.archive(fdb5::Key({{"a", "1"}, {"b", "2"}, {"d", "4"}}), "bar", 4);  // crashes
}

when compiled & run as follows:

g++ -o badschema badschema.cpp -lfdb5 -leckit && ./badschema

The reported error is:

terminate called after throwing an instance of 'eckit::SeriousBug'
  what():  SeriousBug: Key::get() failed for [c] in {a=1,b=2,d=4}  in  (/src/fdb/src/fdb5/database/Key.cc +192 get)

I.e. FDB tries to get the value for "c" in the second archive call, I guess because it accidentally tries to match it agains the first (instead of the second) schema rule.

I've been in contact with @simondsmart, who suggested to use the schema

[a[b?[c][d]]]

instead. However, the test code fails with the same issue (also the schema doesn't encode that b would be required for d).

Describe the solution you'd like

I'd like to see both of the two schemas above work with the provided example code.

Describe alternatives you've considered

If it's impossible to make those schema work, FDB should generate an understandable error message, explaining that the schema is invalid instead of accepting some keys for storage before crashing with other keys.

Additional context

No response

Organisation

MPIM

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions