Skip to content

Commit 5ba236e

Browse files
committed
runtime: Propagate failure from BasicFileOutputStream::open_file
There was previously no good way to tell if `open_file` was successful, so this can be considered a fix. BREAKING CHANGE: Various classes in `output_serializer`, such as `FileSerializer` and `BasicFileOutputStream` return `[[nodiscard]] bool` from the `open_file()` method. Since this method previously returned `void`, this will cause errors for inheriting classes, and warnings for users. BREAKING CHANGE: Required C++ standard for runtime is bumped from 14 to 17. This shouldn't be a problem for most people.
1 parent fcb915b commit 5ba236e

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

runtime/include/cloe/utility/output_serializer.hpp

+20-5
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@ class BasicFileOutputStream : public OutputStream {
8787
using OutputStream::OutputStream;
8888
virtual ~BasicFileOutputStream() = default;
8989
bool open_stream() final { return false; }
90+
91+
[[nodiscard]]
9092
virtual bool open_file(const std::string& filename, const std::string& default_filename);
93+
9194
void write(const char* s, std::streamsize count) override { ofs_.write(s, count); }
9295
void close_stream() override;
9396

@@ -109,7 +112,10 @@ class FilteringOutputStream : public BasicFileOutputStream {
109112
explicit FilteringOutputStream(Logger logger)
110113
: BasicFileOutputStream(logger), filter_(), out_(&filter_) {}
111114
virtual ~FilteringOutputStream() = default;
115+
116+
[[nodiscard]]
112117
bool open_file(const std::string& filename, const std::string& default_filename) override;
118+
113119
void write(const char* s, std::streamsize count) override { out_.write(s, count); }
114120
void close_stream() override;
115121

@@ -175,9 +181,12 @@ class FileSerializer {
175181
, serializer_((void (OutputStream::*)(const char*, std::streamsize)) & TOutputStream::write,
176182
&outputstream_) {}
177183
virtual ~FileSerializer() = default;
178-
virtual void open_file(const std::string& filename, const std::string& default_filename) {
179-
outputstream_.open_file(filename, default_filename);
184+
185+
[[nodiscard]]
186+
virtual bool open_file(const std::string& filename, const std::string& default_filename) {
187+
return outputstream_.open_file(filename, default_filename);
180188
}
189+
181190
virtual void serialize(TSerializerArgs... args) { serializer_.serialize(args...); }
182191
virtual void close_file() { outputstream_.close_stream(); }
183192

@@ -194,10 +203,16 @@ class SequentialFileSerializer
194203

195204
public:
196205
using base::base;
197-
void open_file(const std::string& filename, const std::string& default_filename) override {
198-
base::open_file(filename, default_filename);
199-
on_file_opened();
206+
207+
[[nodiscard]]
208+
bool open_file(const std::string& filename, const std::string& default_filename) override {
209+
bool ok = base::open_file(filename, default_filename);
210+
if (ok) {
211+
on_file_opened();
212+
}
213+
return ok;
200214
}
215+
201216
void close_file() override {
202217
on_file_closing();
203218
base::close_file();

runtime/include/cloe/utility/output_serializer_json.hpp

+9-3
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@ class SimpleJsonSerializer : public AbstractJsonSerializer<const Json&, bool> {
8484
class JsonFileSerializer {
8585
public:
8686
virtual ~JsonFileSerializer() = default;
87-
virtual void open_file(const std::string& filename) = 0;
87+
88+
[[nodiscard]]
89+
virtual bool open_file(const std::string& filename) = 0;
90+
8891
virtual void serialize(const Json& j) = 0;
8992
virtual void close_file() = 0;
9093

@@ -105,11 +108,14 @@ class JsonFileSerializerImpl
105108
JsonFileSerializerImpl(Logger logger) : file_base(logger), JsonFileSerializer() {}
106109
virtual ~JsonFileSerializerImpl() = default;
107110
using file_base::open_file;
108-
void open_file(const std::string& filename) override {
111+
112+
[[nodiscard]]
113+
bool open_file(const std::string& filename) override {
109114
std::string default_name = this->outputstream_.make_default_filename(
110115
this->serializer_.make_default_filename(default_filename));
111-
file_base::open_file(filename, default_name);
116+
return file_base::open_file(filename, default_name);
112117
}
118+
113119
using file_base::serialize;
114120
void serialize(const Json& j) override {
115121
file_base::serialize(j, prepend_delimiter);

0 commit comments

Comments
 (0)