Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/fdb5/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ list( APPEND fdb5_srcs
api/FDBFactory.h
api/FDBStats.cc
api/FDBStats.h
api/exceptions/SchemaError.cc
api/exceptions/SchemaError.h
api/LocalFDB.cc
api/LocalFDB.h
api/RandomFDB.cc
Expand Down
18 changes: 18 additions & 0 deletions src/fdb5/api/exceptions/SchemaError.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* (C) Copyright 2026- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
* In applying this licence, ECMWF does not waive the privileges and immunities
* granted to it by virtue of its status as an intergovernmental organisation nor
* does it submit to any jurisdiction.
*/

#include "fdb5/api/exceptions/SchemaError.h"

namespace fdb5 {

SchemaError::SchemaError(const std::string& path, const std::string& what, size_t line) :
eckit::StreamParser::Error(path + ": " + what, line) {}

} // namespace fdb5
26 changes: 26 additions & 0 deletions src/fdb5/api/exceptions/SchemaError.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* (C) Copyright 2026- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
* In applying this licence, ECMWF does not waive the privileges and immunities
* granted to it by virtue of its status as an intergovernmental organisation nor
* does it submit to any jurisdiction.
*/

#pragma once

#include <cstddef>
#include <string>

#include "eckit/parser/StreamParser.h"

namespace fdb5 {

class SchemaError : public eckit::StreamParser::Error {
public:

SchemaError(const std::string& path, const std::string& what, size_t line = 0);
};

} // namespace fdb5
23 changes: 13 additions & 10 deletions src/fdb5/rules/Schema.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@
*/

#include <cstddef>
#include <fstream>
#include <iostream>
#include <memory>
#include <mutex>
#include <optional>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
Expand All @@ -27,6 +24,7 @@
#include "eckit/utils/Tokenizer.h"

#include "fdb5/LibFdb5.h"
#include "fdb5/api/exceptions/SchemaError.h"
#include "fdb5/database/Key.h"
#include "fdb5/database/WriteVisitor.h"
#include "fdb5/rules/Predicate.h"
Expand Down Expand Up @@ -190,23 +188,28 @@ void Schema::load(const eckit::PathName& path, const bool replace) {

LOG_DEBUG_LIB(LibFdb5) << "Loading FDB rules from " << path << std::endl;

std::ifstream in(path.localPath());
if (!in) {
auto ex = eckit::CantOpenFile(path);
ex.dumpStackTrace();
throw ex;
// Constructing the parser opens `path`, so a missing file is reported
// (as eckit::CantOpenFile) before any existing rules are cleared.
SchemaParser parser(path);

if (replace) {
clear();
}

load(in, replace);
parser.parse(rules_, registry_);

check();
}

void Schema::load(std::istream& s, const bool replace) {

SchemaParser parser(s);

if (replace) {
clear();
}

SchemaParser(s).parse(rules_, registry_);
parser.parse(rules_, registry_);

check();
}
Expand Down
Loading
Loading