XS Framework
A 3DS homebrew development framework.
 
Loading...
Searching...
No Matches
errors.hpp
Go to the documentation of this file.
1// xs_errors.h
2#pragma once
3#include <3ds.h>
4#include <string>
5#include <unordered_map>
6
7namespace xs::errors {
8
9// Lookup tables
10static const std::unordered_map<int, const char *> levelNames = {
11 {0, "Success"}, {1, "Info"}, {0x1F, "Fatal"}, {0x1E, "Reset"}, {0x1D, "Reinitialize"}, {0x1C, "Usage"}, {0x1B, "Permanent"}, {0x1A, "Temporary"}, {0x19, "Status"}};
12
13static const std::unordered_map<int, const char *> summaryNames = {
14 {0, "Success"},
15 {1, "No operation"},
16 {2, "Would block"},
17 {3, "Out of resource"},
18 {4, "Not found"},
19 {5, "Invalid state"},
20 {6, "Not supported"},
21 {7, "Invalid argument"},
22 {8, "Wrong argument"},
23 {9, "Canceled"},
24 {10, "Status changed"},
25 {11, "Internal"},
26 {63, "Invalid result value"}};
27
28static const std::unordered_map<int, const char *> moduleNames = {
29 {0, "Common"},
30 {1, "Kernel"},
31 {2, "Util"},
32 {3, "File Server"},
33 {4, "Loader Server"},
34 {5, "TCB"},
35 {6, "OS"},
36 {7, "DBG"},
37 {8, "DMNT"},
38 {9, "PDN"},
39 {10, "GSP"},
40 {11, "I2C"},
41 {12, "GPIO"},
42 {13, "DD"},
43 {14, "Codec"},
44 {15, "SPI"},
45 {16, "PXI"},
46 {17, "FS"},
47 {18, "DI"},
48 {19, "HID"},
49 {20, "CAM"},
50 {21, "PI"},
51 {22, "PM"},
52 {23, "PM Low"},
53 {24, "FSI"},
54 {25, "SRV"},
55 {26, "NDM"},
56 {27, "NWM"},
57 {28, "SOC"},
58 {29, "LDR"},
59 {30, "ACC"},
60 {31, "ROMFS"},
61 {32, "AM"},
62 {33, "HIO"},
63 {34, "Updater"},
64 {35, "MIC"},
65 {36, "FND"},
66 {37, "MP"},
67 {38, "MPWL"},
68 {39, "AC"},
69 {40, "HTTP"},
70 {41, "DSP"},
71 {42, "SND"},
72 {43, "DLP"},
73 {44, "HIO Low"},
74 {45, "CSND"},
75 {46, "SSL"},
76 {47, "AM Low"},
77 {48, "NEX"},
78 {49, "Friends"},
79 {50, "RDT"},
80 {51, "Applet"},
81 {52, "NIM"},
82 {53, "PTM"},
83 {54, "MIDI"},
84 {55, "MC"},
85 {56, "SWC"},
86 {57, "FATFS"},
87 {58, "NGC"},
88 {59, "Card"},
89 {60, "CardNOR"},
90 {61, "SDMC"},
91 {62, "BOSS"},
92 {63, "DBM"},
93 {64, "Config"},
94 {65, "PS"},
95 {66, "CEC"},
96 {67, "IR"},
97 {68, "UDS"},
98 {69, "PL"},
99 {70, "CUP"},
100 {71, "Gyroscope"},
101 {72, "MCU"},
102 {73, "NS"},
103 {74, "News"},
104 {75, "RO"},
105 {76, "GD"},
106 {77, "Card SPI"},
107 {78, "EC"},
108 {79, "Web Browser"},
109 {80, "Test"},
110 {81, "ENC"},
111 {82, "PIA"},
112 {83, "ACT"},
113 {84, "VCTL"},
114 {85, "OLV"},
115 {86, "NEIA"},
116 {87, "NPNS"},
117 {90, "AVD"},
118 {91, "L2B"},
119 {92, "MVD"},
120 {93, "NFC"},
121 {94, "UART"},
122 {95, "SPM"},
123 {96, "QTM"},
124 {97, "NFP"},
125 {254, "Application"},
126 {255, "Invalid"}};
127
128static const std::unordered_map<int, const char *> descriptionNames = {
129 {0, "Success"},
130 {0x3FF, "Invalid result value"},
131 {0x3FE, "Timeout"},
132 {0x3FD, "Out of range"},
133 {0x3FC, "Already exists"},
134 {0x3FB, "Cancel requested"},
135 {0x3FA, "Not found"},
136 {0x3F9, "Already initialized"},
137 {0x3F8, "Not initialized"},
138 {0x3F7, "Invalid handle"},
139 {0x3F6, "Invalid pointer"},
140 {0x3F5, "Invalid address"},
141 {0x3F4, "Not implemented"},
142 {0x3F3, "Out of memory"},
143 {0x3F2, "Misaligned size"},
144 {0x3F1, "Misaligned address"},
145 {0x3F0, "Busy"},
146 {0x3EF, "No data"},
147 {0x3EE, "Invalid combination"},
148 {0x3ED, "Invalid enum value"},
149 {0x3EC, "Invalid size"},
150 {0x3EB, "Already done"},
151 {0x3EA, "Not authorized"},
152 {0x3E9, "Too large"},
153 {0x3E8, "Invalid selection"}};
154
155inline std::string decode(Result res) {
156 int lvl = R_LEVEL(res);
157 int sum = R_SUMMARY(res);
158 int mod = R_MODULE(res);
159 int desc = R_DESCRIPTION(res);
160
161 const char *lvlStr = levelNames.count(lvl) ? levelNames.at(lvl) : "Unknown";
162 const char *sumStr =
163 summaryNames.count(sum) ? summaryNames.at(sum) : "Unknown";
164 const char *modStr = moduleNames.count(mod) ? moduleNames.at(mod) : "Unknown";
165 const char *descStr =
166 descriptionNames.count(desc) ? descriptionNames.at(desc) : "Unknown";
167
168 char buf[512];
169 snprintf(buf, sizeof(buf),
170 "Result: 0x%08lX\n"
171 " Level: %s (%d)\n"
172 " Summary: %s (%d)\n"
173 " Module: %s (%d)\n"
174 " Description: %s (%d)",
175 res, lvlStr, lvl, sumStr, sum, modStr, mod, descStr, desc);
176
177 return std::string(buf);
178}
179
180inline void show(Result res, bool softwareReset = false) {
181 errorConf err;
182 errorInit(&err, ERROR_TEXT_WORD_WRAP, CFG_LANGUAGE_EN);
183 err.softwareReset = softwareReset;
184 std::string msg = decode(res);
185 errorText(&err, msg.c_str());
186 errorDisp(&err);
187}
188
189inline void show(const char *msg, bool softwareReset = false) {
190 errorConf err;
191 errorInit(&err, ERROR_TEXT_WORD_WRAP, CFG_LANGUAGE_EN);
192 err.softwareReset = softwareReset;
193 errorText(&err, msg);
194 errorDisp(&err);
195}
196
197} // namespace xs::errors
Definition errors.hpp:7
static const std::unordered_map< int, const char * > descriptionNames
Definition errors.hpp:128
void show(Result res, bool softwareReset=false)
Definition errors.hpp:180
std::string decode(Result res)
Definition errors.hpp:155
static const std::unordered_map< int, const char * > levelNames
Definition errors.hpp:10
static const std::unordered_map< int, const char * > moduleNames
Definition errors.hpp:28
static const std::unordered_map< int, const char * > summaryNames
Definition errors.hpp:13