wowlib 0.0.0
Read & write World of Warcraft client files — a C++26 core
Loading...
Searching...
No Matches
error.hpp
Go to the documentation of this file.
1#pragma once
2
7
8#include <cstdint>
9#include <expected>
10#include <string>
11
13
14namespace wowlib {
51
55 constexpr std::string_view to_string(ErrorCode code) {
56 return enumName(code);
57 }
58
63 struct Error {
65 std::string message;
66
69 std::uint32_t nativeError = 0;
70 };
71
84 inline std::string to_string(const Error& error) {
85 std::string out{to_string(error.code)};
86 out += ": ";
87 out += error.message;
88 if (error.nativeError != 0) {
89 out += " (native ";
90 out += std::to_string(error.nativeError);
91 out += ')';
92 }
93 return out;
94 }
95
99 template <typename T>
100 using Result = std::expected<T, Error>;
101
107 inline std::unexpected<Error> makeError(ErrorCode code, std::string message, std::uint32_t nativeError = 0) {
108 return std::unexpected(Error{code, std::move(message), nativeError});
109 }
110}
constexpr std::string_view to_string(ErrorCode code)
The enumerator spelling of code, obtained via reflection.
Definition error.hpp:55
std::expected< T, Error > Result
Every fallible wowlib operation returns Result<T>; bindings translate the error branch into a target-...
Definition error.hpp:100
std::unexpected< Error > makeError(ErrorCode code, std::string message, std::uint32_t nativeError=0)
Shorthand for constructing the error branch of a Result.
Definition error.hpp:107
ErrorCode
Machine-readable failure category carried by every Error.
Definition error.hpp:18
@ FdidNotResolvable
No path is known for the given FileDataID.
Definition error.hpp:24
@ TableUnknown
The schema catalog knows no table of the requested name.
Definition error.hpp:49
@ FileNotFound
The file exists nowhere in the overlay or storage.
Definition error.hpp:22
@ StorageOpenFailed
The client storage (MPQ chain / CASC) failed to initialize.
Definition error.hpp:19
@ EncryptedContent
Content is behind an unknown TACT encryption key.
Definition error.hpp:31
@ UnsupportedClientVersion
No format instantiation exists for the requested client version.
Definition error.hpp:42
@ InvalidEntityState
An entity's members disagree (e.g.
Definition error.hpp:40
@ PathNotResolvable
No FileDataID is known for the given path (listfile miss).
Definition error.hpp:23
@ SchemaMismatch
A client-database record layout disagrees with the generated WoWDBDefs schema.
Definition error.hpp:46
@ ListfileParseError
Malformed listfile CSV content.
Definition error.hpp:25
@ SchemaBlobInvalid
A WDBS schema blob (or WoWDBDefs source) is malformed or truncated.
Definition error.hpp:48
@ TableMagicUnknown
A client-database magic wowlib does not support for the requested version.
Definition error.hpp:45
@ FormatVersionMismatch
The file's version chunk disagrees with the requested version.
Definition error.hpp:41
@ InvalidPath
A path that cannot be normalized/used.
Definition error.hpp:29
@ BackendError
Unclassified StormLib/CascLib failure; see nativeError.
Definition error.hpp:34
@ StorageNotOpen
Operation on a closed or moved-from storage.
Definition error.hpp:21
@ FdidSpaceExhausted
The custom FileDataID allocator ran out of u32 space.
Definition error.hpp:27
@ ListfileIoError
The listfile could not be read or written.
Definition error.hpp:26
@ NotImplemented
Placeholder during phased implementation.
Definition error.hpp:33
@ NotSupported
Operation not supported by this backend/provider.
Definition error.hpp:32
@ OffsetOutOfBounds
An offset array (M2Array) points outside its base buffer.
Definition error.hpp:39
@ ChunkSizeMismatch
A chunk's size disagrees with its binary struct layout.
Definition error.hpp:37
@ TableTruncated
A client-database header, record block or satellite block overruns the file.
Definition error.hpp:44
@ DuplicatePath
Registering a path that already has a FileDataID.
Definition error.hpp:28
@ ArchiveOpenFailed
A single archive within an MPQ chain failed to open.
Definition error.hpp:20
@ ChunkTruncated
A chunk header or payload overruns the file buffer.
Definition error.hpp:36
@ ChunkMissing
A chunk the format requires is absent from the file.
Definition error.hpp:38
@ IoError
Generic filesystem I/O failure (project directory).
Definition error.hpp:30
constexpr std::string_view enumName(E value)
The enumerator name of value, straight from reflection — no handwritten stringification tables anywhe...
Definition reflect.hpp:19
Internal C++26 reflection utilities (<meta> based).
A wowlib operation failure: a machine-readable code, a human-readable message, and the originating na...
Definition error.hpp:63
std::uint32_t nativeError
Raw GetCascError()/GetLastError() value from the native library, 0 if not applicable.
Definition error.hpp:69
ErrorCode code
The failure category.
Definition error.hpp:64
std::string message
Human-readable description of what failed, with context.
Definition error.hpp:65