[ox] Cleanup some old style error handling
This commit is contained in:
parent
6664462391
commit
a22823e3b4
@ -445,7 +445,7 @@ Result<StatInfo> FileStoreTemplate<size_t>::stat(InodeId_t id) {
|
||||
inode->fileType,
|
||||
});
|
||||
}
|
||||
return Result<StatInfo>({}, OxError(0));
|
||||
return {};
|
||||
}
|
||||
|
||||
template<typename size_t>
|
||||
@ -486,9 +486,9 @@ Result<typename FileStoreTemplate<size_t>::InodeId_t> FileStoreTemplate<size_t>:
|
||||
return inode;
|
||||
}
|
||||
}
|
||||
return {0, OxError(2)};
|
||||
return OxError(2);
|
||||
}
|
||||
return {0, OxError(1)};
|
||||
return OxError(1);
|
||||
}
|
||||
|
||||
template<typename size_t>
|
||||
|
4
deps/ox/src/ox/fs/filesystem/directory.hpp
vendored
4
deps/ox/src/ox/fs/filesystem/directory.hpp
vendored
@ -319,7 +319,7 @@ Result<typename FileStore::InodeId_t> Directory<FileStore, InodeId_t>::findEntry
|
||||
auto buff = m_fs.read(m_inodeId).template to<Buffer>();
|
||||
if (!buff.valid()) {
|
||||
oxTrace("ox::fs::Directory::findEntry::fail") << "Could not findEntry directory buffer";
|
||||
return {0, OxError(2)};
|
||||
return OxError(2);
|
||||
}
|
||||
oxTrace("ox::fs::Directory::findEntry") << "Found directory buffer, size:" << buff.size();
|
||||
for (auto i = buff->iterator(); i.valid(); i.next()) {
|
||||
@ -335,7 +335,7 @@ Result<typename FileStore::InodeId_t> Directory<FileStore, InodeId_t>::findEntry
|
||||
}
|
||||
}
|
||||
oxTrace("ox::fs::Directory::findEntry::fail") << "Entry not present";
|
||||
return {0, OxError(1)};
|
||||
return OxError(1);
|
||||
}
|
||||
|
||||
template<typename FileStore, typename InodeId_t>
|
||||
|
52
deps/ox/src/ox/fs/filesystem/filesystem.hpp
vendored
52
deps/ox/src/ox/fs/filesystem/filesystem.hpp
vendored
@ -316,9 +316,8 @@ template<typename FileStore, typename Directory>
|
||||
Error FileSystemTemplate<FileStore, Directory>::write(const char *path, void *buffer, uint64_t size, uint8_t fileType) noexcept {
|
||||
auto [inode, err] = find(path);
|
||||
if (err) {
|
||||
auto generated = m_fs.generateInodeId();
|
||||
oxReturnError(generated.error);
|
||||
inode = generated.value;
|
||||
oxRequire(generatedId, m_fs.generateInodeId());
|
||||
inode = generatedId;
|
||||
}
|
||||
auto rootDir = this->rootDir();
|
||||
oxReturnError(rootDir.error);
|
||||
@ -334,22 +333,19 @@ Error FileSystemTemplate<FileStore, Directory>::write(uint64_t inode, void *buff
|
||||
|
||||
template<typename FileStore, typename Directory>
|
||||
Result<FileStat> FileSystemTemplate<FileStore, Directory>::stat(uint64_t inode) noexcept {
|
||||
auto s = m_fs.stat(inode);
|
||||
oxRequire(s, m_fs.stat(inode));
|
||||
FileStat out;
|
||||
out.inode = s.value.inode;
|
||||
out.links = s.value.links;
|
||||
out.size = s.value.size;
|
||||
out.fileType = s.value.fileType;
|
||||
return {out, s.error};
|
||||
out.inode = s.inode;
|
||||
out.links = s.links;
|
||||
out.size = s.size;
|
||||
out.fileType = s.fileType;
|
||||
return out;
|
||||
}
|
||||
|
||||
template<typename FileStore, typename Directory>
|
||||
Result<FileStat> FileSystemTemplate<FileStore, Directory>::stat(const char *path) noexcept {
|
||||
auto inode = find(path);
|
||||
if (inode.error) {
|
||||
return {{}, inode.error};
|
||||
}
|
||||
return stat(inode.value);
|
||||
oxRequire(inode, find(path));
|
||||
return stat(inode);
|
||||
}
|
||||
|
||||
template<typename FileStore, typename Directory>
|
||||
@ -385,38 +381,26 @@ bool FileSystemTemplate<FileStore, Directory>::valid() const noexcept {
|
||||
template<typename FileStore, typename Directory>
|
||||
Result<typename FileSystemTemplate<FileStore, Directory>::FileSystemData> FileSystemTemplate<FileStore, Directory>::fileSystemData() const noexcept {
|
||||
FileSystemData fd;
|
||||
auto err = m_fs.read(InodeFsData, &fd, sizeof(fd));
|
||||
if (err != 0) {
|
||||
return {fd, err};
|
||||
}
|
||||
oxReturnError(m_fs.read(InodeFsData, &fd, sizeof(fd)));
|
||||
return fd;
|
||||
}
|
||||
|
||||
template<typename FileStore, typename Directory>
|
||||
Result<uint64_t> FileSystemTemplate<FileStore, Directory>::find(const char *path) const noexcept {
|
||||
auto fd = fileSystemData();
|
||||
if (fd.error) {
|
||||
return {0, fd.error};
|
||||
}
|
||||
oxRequire(fd, fileSystemData());
|
||||
// return root as a special case
|
||||
if (ox_strcmp(path, "/") == 0) {
|
||||
return static_cast<uint64_t>(fd.value.rootDirInode);
|
||||
return static_cast<uint64_t>(fd.rootDirInode);
|
||||
}
|
||||
Directory rootDir(m_fs, fd.value.rootDirInode);
|
||||
auto inode = rootDir.find(path);
|
||||
if (inode.error) {
|
||||
return {0, inode.error};
|
||||
}
|
||||
return inode.value;
|
||||
Directory rootDir(m_fs, fd.rootDirInode);
|
||||
oxRequire(out, rootDir.find(path));
|
||||
return static_cast<uint64_t>(out);
|
||||
}
|
||||
|
||||
template<typename FileStore, typename Directory>
|
||||
Result<Directory> FileSystemTemplate<FileStore, Directory>::rootDir() const noexcept {
|
||||
auto fd = fileSystemData();
|
||||
if (fd.error) {
|
||||
return {{}, fd.error};
|
||||
}
|
||||
return Directory(m_fs, fd.value.rootDirInode);
|
||||
oxRequire(fd, fileSystemData());
|
||||
return Directory(m_fs, fd.rootDirInode);
|
||||
}
|
||||
|
||||
extern template class FileSystemTemplate<FileStore16, Directory16>;
|
||||
|
@ -136,7 +136,8 @@ Result<FileStat> PassThroughFS::stat(const char *path) noexcept {
|
||||
uint64_t size = type == FileType_Directory ? 0 : std::filesystem::file_size(p, ec);
|
||||
oxTrace("ox::fs::PassThroughFS::stat") << ec.message().c_str() << path;
|
||||
oxTrace("ox::fs::PassThroughFS::stat::size") << path << size;
|
||||
return {{0, 0, size, type}, OxError(ec.value())};
|
||||
oxReturnError(OxError(ec.value()));
|
||||
return FileStat{0, 0, size, type};
|
||||
}
|
||||
|
||||
uint64_t PassThroughFS::spaceNeeded(uint64_t size) noexcept {
|
||||
|
6
deps/ox/src/ox/mc/intops.hpp
vendored
6
deps/ox/src/ox/mc/intops.hpp
vendored
@ -120,7 +120,7 @@ Result<I> decodeInteger(uint8_t buff[9], std::size_t buffLen, std::size_t *bytes
|
||||
*bytesRead = bytes;
|
||||
I out = 0;
|
||||
memcpy(&out, &buff[1], sizeof(I));
|
||||
return {LittleEndian<I>(out), OxError(0)};
|
||||
return static_cast<I>(LittleEndian<I>(out));
|
||||
} else if (buffLen >= bytes) {
|
||||
*bytesRead = bytes;
|
||||
uint64_t decoded = 0;
|
||||
@ -138,9 +138,9 @@ Result<I> decodeInteger(uint8_t buff[9], std::size_t buffLen, std::size_t *bytes
|
||||
decoded |= sign << (Bits<I> - 1);
|
||||
memcpy(&out, &decoded, sizeof(out));
|
||||
}
|
||||
return {out, OxError(0)};
|
||||
return out;
|
||||
}
|
||||
return {0, OxError(1)};
|
||||
return OxError(1);
|
||||
}
|
||||
|
||||
template<typename I>
|
||||
|
2
deps/ox/src/ox/mc/presenceindicator.cpp
vendored
2
deps/ox/src/ox/mc/presenceindicator.cpp
vendored
@ -21,7 +21,7 @@ Result<bool> FieldPresenceIndicator::get(std::size_t i) const {
|
||||
if (i / 8 < m_maskLen) {
|
||||
return (m_mask[i / 8] >> (i % 8)) & 1;
|
||||
} else {
|
||||
return {false, OxError(MC_PRESENCEMASKOUTBOUNDS)};
|
||||
return OxError(MC_PRESENCEMASKOUTBOUNDS);
|
||||
}
|
||||
}
|
||||
|
||||
|
4
deps/ox/src/ox/model/descwrite.hpp
vendored
4
deps/ox/src/ox/model/descwrite.hpp
vendored
@ -236,8 +236,8 @@ void TypeDescWriter::setTypeInfo(const char *name, int) {
|
||||
template<typename T>
|
||||
Result<DescriptorType*> buildTypeDef(T *val) {
|
||||
TypeDescWriter writer;
|
||||
Error err = model(&writer, val);
|
||||
return {writer.definition(), err};
|
||||
oxReturnError(model(&writer, val));
|
||||
return writer.definition();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
2
deps/ox/src/ox/oc/read.hpp
vendored
2
deps/ox/src/ox/oc/read.hpp
vendored
@ -199,7 +199,7 @@ template<typename T>
|
||||
Result<std::unique_ptr<T>> readOC(const char *json) {
|
||||
auto val = std::make_unique<T>();
|
||||
oxReturnError(readOC(json, ox_strlen(json), val.get()));
|
||||
return {std::move(val), OxError(0)};
|
||||
return std::move(val);
|
||||
}
|
||||
|
||||
}
|
||||
|
15
deps/ox/src/ox/std/error.hpp
vendored
15
deps/ox/src/ox/std/error.hpp
vendored
@ -59,7 +59,7 @@ struct [[nodiscard]] Error {
|
||||
template<typename T>
|
||||
struct [[nodiscard]] Result {
|
||||
|
||||
using type = T;
|
||||
using type = typename ox::remove_reference<T>::type;
|
||||
|
||||
T value;
|
||||
Error error;
|
||||
@ -70,14 +70,17 @@ struct [[nodiscard]] Result {
|
||||
constexpr Result(const Error &error) noexcept: error(error) {
|
||||
}
|
||||
|
||||
constexpr Result(T value, const Error &error = OxError(0)) noexcept: value(ox::move(value)), error(error) {
|
||||
constexpr Result(const type &value, const Error &error = OxError(0)) noexcept: value(const_cast<type&>(value)), error(error) {
|
||||
}
|
||||
|
||||
explicit constexpr operator const T&() const noexcept {
|
||||
constexpr Result(type &&value, const Error &error = OxError(0)) noexcept: value(ox::move(value)), error(error) {
|
||||
}
|
||||
|
||||
explicit constexpr operator const type&() const noexcept {
|
||||
return value;
|
||||
}
|
||||
|
||||
explicit constexpr operator T&() noexcept {
|
||||
explicit constexpr operator type&() noexcept {
|
||||
return value;
|
||||
}
|
||||
|
||||
@ -86,12 +89,12 @@ struct [[nodiscard]] Result {
|
||||
return error == 0;
|
||||
}
|
||||
|
||||
constexpr Error get(T *val) noexcept {
|
||||
constexpr Error get(type *val) noexcept {
|
||||
*val = value;
|
||||
return error;
|
||||
}
|
||||
|
||||
constexpr Error moveTo(T *val) noexcept {
|
||||
constexpr Error moveTo(type *val) noexcept {
|
||||
*val = ox::move(value);
|
||||
return error;
|
||||
}
|
||||
|
2
deps/ox/src/ox/std/hashmap.hpp
vendored
2
deps/ox/src/ox/std/hashmap.hpp
vendored
@ -144,7 +144,7 @@ template<typename K, typename T>
|
||||
Result<const T*> HashMap<K, T>::at(K k) const {
|
||||
auto p = access(m_pairs, k);
|
||||
if (!p) {
|
||||
return {nullptr, OxError(1, "Value not found for key")};
|
||||
return OxError(1, "Value not found for key");
|
||||
}
|
||||
return &p->value;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user