| ... | @@ -1,3 +1,5 @@ | ... | @@ -1,3 +1,5 @@ |
| | 1 | const testing = @import("std").testing; |
| | 2 | |
| 1 | const high_bit = 1 << @typeInfo(usize).Int.bits - 1; | 3 | const high_bit = 1 << @typeInfo(usize).Int.bits - 1; |
| 2 | | 4 | |
| 3 | pub const Status = enum(usize) { | 5 | pub const Status = enum(usize) { |
| ... | @@ -139,4 +141,71 @@ pub const Status = enum(usize) { | ... | @@ -139,4 +141,71 @@ pub const Status = enum(usize) { |
| 139 | WarnResetRequired = 7, | 141 | WarnResetRequired = 7, |
| 140 | | 142 | |
| 141 | _, | 143 | _, |
| | 144 | |
| | 145 | pub const EfiError = error{ |
| | 146 | LoadError, |
| | 147 | InvalidParameter, |
| | 148 | Unsupported, |
| | 149 | BadBufferSize, |
| | 150 | BufferTooSmall, |
| | 151 | NotReady, |
| | 152 | DeviceError, |
| | 153 | WriteProtected, |
| | 154 | OutOfResources, |
| | 155 | VolumeCorrupted, |
| | 156 | VolumeFull, |
| | 157 | NoMedia, |
| | 158 | MediaChanged, |
| | 159 | NotFound, |
| | 160 | AccessDenied, |
| | 161 | NoResponse, |
| | 162 | NoMapping, |
| | 163 | Timeout, |
| | 164 | NotStarted, |
| | 165 | AlreadyStarted, |
| | 166 | Aborted, |
| | 167 | IcmpError, |
| | 168 | TftpError, |
| | 169 | ProtocolError, |
| | 170 | IncompatibleVersion, |
| | 171 | SecurityViolation, |
| | 172 | CrcError, |
| | 173 | EndOfMedia, |
| | 174 | EndOfFile, |
| | 175 | InvalidLanguage, |
| | 176 | CompromisedData, |
| | 177 | IpAddressConflict, |
| | 178 | HttpError, |
| | 179 | NetworkUnreachable, |
| | 180 | HostUnreachable, |
| | 181 | ProtocolUnreachable, |
| | 182 | PortUnreachable, |
| | 183 | ConnectionFin, |
| | 184 | ConnectionReset, |
| | 185 | ConnectionRefused, |
| | 186 | WarnUnknownGlyph, |
| | 187 | WarnDeleteFailure, |
| | 188 | WarnWriteFailure, |
| | 189 | WarnBufferTooSmall, |
| | 190 | WarnStaleData, |
| | 191 | WarnFileSystem, |
| | 192 | WarnResetRequired, |
| | 193 | }; |
| | 194 | |
| | 195 | pub fn err(self: Status) EfiError!void { |
| | 196 | inline for (@typeInfo(EfiError).ErrorSet.?) |efi_err| { |
| | 197 | if (self == @field(Status, efi_err.name)) { |
| | 198 | return @field(EfiError, efi_err.name); |
| | 199 | } |
| | 200 | } |
| | 201 | // self is .Success |
| | 202 | } |
| 142 | }; | 203 | }; |
| | 204 | |
| | 205 | test "status" { |
| | 206 | var st: Status = .DeviceError; |
| | 207 | try testing.expectError(error.DeviceError, st.err()); |
| | 208 | |
| | 209 | st = .Success; |
| | 210 | try st.err(); |
| | 211 | } |