libnx  v4.2.2
error.h
Go to the documentation of this file.
1 /**
2  * @file error.h
3  * @brief Wrapper for using the error LibraryApplet.
4  * @author StuntHacks, yellows8
5  * @copyright libnx Authors
6  */
7 #pragma once
8 #include "../types.h"
9 #include "../services/set.h"
10 
11 /// Error type for ErrorCommonHeader.type.
12 typedef enum {
13  ErrorType_Normal = 0, ///< Normal
14  ErrorType_System = 1, ///< System
15  ErrorType_Application = 2, ///< Application
16  ErrorType_Eula = 3, ///< EULA
17  ErrorType_Pctl = 4, ///< Parental Controls
18  ErrorType_Record = 5, ///< Record
19  ErrorType_SystemUpdateEula = 8, ///< SystemUpdateEula
20 } ErrorType;
21 
22 /// Stores error-codes which are displayed as XXXX-XXXX, low for the former and desc for the latter.
23 typedef struct {
24  u32 low; ///< The module portion of the error, normally this should be set to module + 2000.
25  u32 desc; ///< The error description.
26 } ErrorCode;
27 
28 /// Error type for ErrorContext.type
29 typedef enum {
30  ErrorContextType_None = 0, ///< None
31  ErrorContextType_Http = 1, ///< Http
32  ErrorContextType_FileSystem = 2, ///< FileSystem
33  ErrorContextType_WebMediaPlayer = 3, ///< WebMediaPlayer
34  ErrorContextType_LocalContentShare = 4, ///< LocalContentShare
36 
37 /// Error context.
38 typedef struct {
39  u8 type; ///< Type, see \ref ErrorContextType.
40  u8 pad[7]; ///< Padding
41  u8 data[0x1f4]; ///< Data
42  Result res; ///< Result
43 } ErrorContext;
44 
45 /// Common header for the start of the arg storage.
46 typedef struct {
47  u8 type; ///< Type, see \ref ErrorType.
48  u8 jumpFlag; ///< When clear, this indicates WithoutJump.
49  u8 unk_x2[3]; ///< Unknown
50  u8 contextFlag; ///< When set with ::ErrorType_Normal, indicates that an additional storage is pushed for \ref ErrorResultBacktrace. [4.0.0+] Otherwise, when set indicates that an additional storage is pushed for \ref ErrorContext.
51  u8 resultFlag; ///< ErrorCommonArg: When clear, errorCode is used, otherwise the applet generates the error-code from res.
52  u8 contextFlag2; ///< Similar to contextFlag except for ErrorCommonArg, indicating \ref ErrorContext is used.
54 
55 /// Common error arg data.
56 typedef struct {
57  ErrorCommonHeader hdr; ///< Common header.
58  ErrorCode errorCode; ///< \ref ErrorCode
59  Result res; ///< Result
61 
62 /// Error arg data for certain errors with module PCTL.
63 typedef struct {
64  ErrorCommonHeader hdr; ///< Common header.
65  Result res; ///< Result
66 } ErrorPctlArg;
67 
68 /// ResultBacktrace
69 typedef struct {
70  s32 count; ///< Total entries in the backtrace array.
71  Result backtrace[0x20]; ///< Result backtrace.
73 
74 /// Error arg data for EULA.
75 typedef struct {
76  ErrorCommonHeader hdr; ///< Common header.
77  SetRegion regionCode; ///< \ref SetRegion
78 } ErrorEulaArg;
79 
80 /// Additional input storage data for \ref errorSystemUpdateEulaShow.
81 typedef struct {
82  u8 data[0x20000]; ///< data
84 
85 /// Error arg data for Record.
86 typedef struct {
87  ErrorCommonHeader hdr; ///< Common header.
88  ErrorCode errorCode; ///< \ref ErrorCode
89  u64 timestamp; ///< POSIX timestamp.
91 
92 /// SystemErrorArg
93 typedef struct {
94  ErrorCommonHeader hdr; ///< Common header.
95  ErrorCode errorCode; ///< \ref ErrorCode
96  u64 languageCode; ///< See set.h.
97  char dialogMessage[0x800]; ///< UTF-8 Dialog message.
98  char fullscreenMessage[0x800]; ///< UTF-8 Fullscreen message (displayed when the user clicks on "Details").
100 
101 /// Error system config.
102 typedef struct {
103  ErrorSystemArg arg; ///< Arg data.
104  ErrorContext ctx; ///< Optional error context.
106 
107 /// ApplicationErrorArg
108 typedef struct {
109  ErrorCommonHeader hdr; ///< Common header.
110  u32 errorNumber; ///< Raw decimal error number which is displayed in the dialog.
111  u64 languageCode; ///< See set.h.
112  char dialogMessage[0x800]; ///< UTF-8 Dialog message.
113  char fullscreenMessage[0x800]; ///< UTF-8 Fullscreen message (displayed when the user clicks on "Details").
115 
116 /// Error application config.
117 typedef struct {
118  ErrorApplicationArg arg; ///< Arg data.
120 
121 /**
122  * @brief Creates an \ref ErrorCode.
123  * @param low The module portion of the error, normally this should be set to module + 2000.
124  * @param desc The error description.
125  */
126 static inline ErrorCode errorCodeCreate(u32 low, u32 desc) {
127  return (ErrorCode){low, desc};
128 }
129 
130 /**
131  * @brief Creates an \ref ErrorCode with the input Result. Wrapper for \ref errorCodeCreate.
132  * @param res Input Result.
133  */
135  return errorCodeCreate(2000 + R_MODULE(res), R_DESCRIPTION(res));
136 }
137 
138 /**
139  * @brief Creates an invalid \ref ErrorCode.
140  */
141 static inline ErrorCode errorCodeCreateInvalid(void) {
142  return (ErrorCode){0};
143 }
144 
145 /**
146  * @brief Checks whether the input ErrorCode is valid.
147  * @param errorCode \ref ErrorCode
148  */
149 static inline bool errorCodeIsValid(ErrorCode errorCode) {
150  return errorCode.low!=0;
151 }
152 
153 /**
154  * @brief Launches the applet for displaying the specified Result.
155  * @param res Result
156  * @param jumpFlag Jump flag, normally this is true.
157  * @param ctx Optional \ref ErrorContext, can be NULL. Unused when jumpFlag=false. Ignored on pre-4.0.0, since it's only available for [4.0.0+].
158  * @note Sets the following fields: jumpFlag and contextFlag2. Uses ::ErrorType_Normal normally.
159  * @note For module=PCTL errors with desc 100-119 this sets uses ::ErrorType_Pctl, in which case the applet will display the following special dialog: "This software is restricted by Parental Controls".
160  * @note If the input Result is 0xC8A2, the applet will display a special dialog regarding the current application requiring a software update, with buttons "Later" and "Restart".
161  * @note [3.0.0+] If the input Result is 0xCAA2, the applet will display a special dialog related to DLC version.
162  * @warning This applet creates an error report that is logged in the system, when not handling the above special dialogs. Proceed at your own risk!
163  */
164 Result errorResultShow(Result res, bool jumpFlag, const ErrorContext* ctx);
165 
166 /**
167  * @brief Launches the applet for displaying the specified ErrorCode.
168  * @param errorCode \ref ErrorCode
169  * @param jumpFlag Jump flag, normally this is true.
170  * @param ctx Optional \ref ErrorContext, can be NULL. Unused when jumpFlag=false. Ignored on pre-4.0.0, since it's only available for [4.0.0+].
171  * @note Sets the following fields: jumpFlag and contextFlag2. resultFlag=1. Uses ::ErrorType_Normal.
172  * @warning This applet creates an error report that is logged in the system. Proceed at your own risk!
173  */
174 Result errorCodeShow(ErrorCode errorCode, bool jumpFlag, const ErrorContext* ctx);
175 
176 /**
177  * @brief Creates an ErrorResultBacktrace struct.
178  * @param backtrace \ref ErrorResultBacktrace struct.
179  * @param count Total number of entries.
180  * @param entries Input array of Result.
181  */
182 Result errorResultBacktraceCreate(ErrorResultBacktrace* backtrace, s32 count, const Result* entries);
183 
184 /**
185  * @brief Launches the applet for \ref ErrorResultBacktrace.
186  * @param backtrace ErrorResultBacktrace struct.
187  * @param res Result
188  * @note Sets the following fields: jumpFlag=1, contextFlag=1, and uses ::ErrorType_Normal.
189  * @warning This applet creates an error report that is logged in the system. Proceed at your own risk!
190  */
192 
193 /**
194  * @brief Launches the applet for displaying the EULA.
195  * @param RegionCode \ref SetRegion
196  * @note Sets the following fields: jumpFlag=1, regionCode, and uses ::ErrorType_Eula.
197  */
198 Result errorEulaShow(SetRegion RegionCode);
199 
200 /**
201  * @brief Launches the applet for displaying the system-update EULA.
202  * @param RegionCode \ref SetRegion
203  * @param eula EULA data. Address must be 0x1000-byte aligned.
204  * @note Sets the following fields: jumpFlag=1, regionCode, and uses ::ErrorType_SystemUpdateEula.
205  */
207 
208 /**
209  * @brief Launches the applet for displaying an error full-screen, using the specified ErrorCode and timestamp.
210  * @param errorCode \ref ErrorCode
211  * @param timestamp POSIX timestamp.
212  * @note Sets the following fields: jumpFlag=1, errorCode, timestamp, and uses ::ErrorType_Record.
213  * @note The applet does not log an error report for this. error*RecordShow is used by qlaunch for displaying previously logged error reports.
214  */
215 Result errorCodeRecordShow(ErrorCode errorCode, u64 timestamp);
216 
217 /**
218  * @brief Launches the applet for displaying an error full-screen, using the specified Result and timestamp.
219  * @param res Result
220  * @param timestamp POSIX timestamp.
221  * @note Wrapper for \ref errorCodeRecordShow, see \ref errorCodeRecordShow notes.
222  */
223 static inline Result errorResultRecordShow(Result res, u64 timestamp) {
224  return errorCodeRecordShow(errorCodeCreateResult(res), timestamp);
225 }
226 
227 /**
228  * @brief Creates an ErrorSystemConfig struct.
229  * @param c ErrorSystemConfig struct.
230  * @param dialog_message UTF-8 dialog message.
231  * @param fullscreen_message UTF-8 fullscreen message, displayed when the user clicks on "Details". Optional, can be NULL (which disables displaying Details).
232  * @note Sets the following fields: {strings}, and uses ::ErrorType_System. The rest are cleared.
233  * @note On pre-5.0.0 this will initialize languageCode by using: setInitialize(), setMakeLanguageCode(SetLanguage_ENUS, ...), and setExit(). This is needed since an empty languageCode wasn't supported until [5.0.0+] (which would also use SetLanguage_ENUS).
234  * @warning This applet creates an error report that is logged in the system. Proceed at your own risk!
235  */
236 Result errorSystemCreate(ErrorSystemConfig* c, const char* dialog_message, const char* fullscreen_message);
237 
238 /**
239  * @brief Launches the applet with the specified config.
240  * @param c ErrorSystemConfig struct.
241  */
243 
244 /**
245  * @brief Sets the error code.
246  * @param c ErrorSystemConfig struct.
247  * @param errorCode \ref ErrorCode
248  */
249 static inline void errorSystemSetCode(ErrorSystemConfig* c, ErrorCode errorCode) {
250  c->arg.errorCode = errorCode;
251 }
252 
253 /**
254  * @brief Sets the error code, using the input Result. Wrapper for \ref errorSystemSetCode.
255  * @param c ErrorSystemConfig struct.
256  * @param res The Result to set.
257  */
258 static inline void errorSystemSetResult(ErrorSystemConfig* c, Result res) {
260 }
261 
262 /**
263  * @brief Sets the LanguageCode.
264  * @param c ErrorSystemConfig struct.
265  * @param LanguageCode LanguageCode, see set.h.
266  */
267 static inline void errorSystemSetLanguageCode(ErrorSystemConfig* c, u64 LanguageCode) {
268  c->arg.languageCode = LanguageCode;
269 }
270 
271 /**
272  * @brief Sets the ErrorContext.
273  * @note Only available on [4.0.0+], on older versions this will return without setting the context.
274  * @param c ErrorSystemConfig struct.
275  * @param ctx ErrorContext, NULL to clear it.
276  */
278 
279 /**
280  * @brief Creates an ErrorApplicationConfig struct.
281  * @param c ErrorApplicationConfig struct.
282  * @param dialog_message UTF-8 dialog message.
283  * @param fullscreen_message UTF-8 fullscreen message, displayed when the user clicks on "Details". Optional, can be NULL (which disables displaying Details).
284  * @note Sets the following fields: jumpFlag=1, {strings}, and uses ::ErrorType_Application. The rest are cleared.
285  * @note On pre-5.0.0 this will initialize languageCode by using: setInitialize(), setMakeLanguageCode(SetLanguage_ENUS, ...), and setExit(). This is needed since an empty languageCode wasn't supported until [5.0.0+] (which would also use SetLanguage_ENUS).
286  * @warning This applet creates an error report that is logged in the system. Proceed at your own risk!
287  */
288 Result errorApplicationCreate(ErrorApplicationConfig* c, const char* dialog_message, const char* fullscreen_message);
289 
290 /**
291  * @brief Launches the applet with the specified config.
292  * @param c ErrorApplicationConfig struct.
293  */
295 
296 /**
297  * @brief Sets the error code number.
298  * @param c ErrorApplicationConfig struct.
299  * @param errorNumber Error code number. Raw decimal error number which is displayed in the dialog.
300  */
301 static inline void errorApplicationSetNumber(ErrorApplicationConfig* c, u32 errorNumber) {
302  c->arg.errorNumber = errorNumber;
303 }
304 
305 /**
306  * @brief Sets the LanguageCode.
307  * @param c ErrorApplicationConfig struct.
308  * @param LanguageCode LanguageCode, see set.h.
309  */
310 static inline void errorApplicationSetLanguageCode(ErrorApplicationConfig* c, u64 LanguageCode) {
311  c->arg.languageCode = LanguageCode;
312 }
313 
errorCodeCreateInvalid
static ErrorCode errorCodeCreateInvalid(void)
Creates an invalid ErrorCode.
Definition: error.h:141
ErrorSystemArg
SystemErrorArg.
Definition: error.h:93
R_MODULE
#define R_MODULE(res)
Returns the module ID of a result code.
Definition: result.h:14
ErrorType_Eula
@ ErrorType_Eula
EULA.
Definition: error.h:16
errorSystemUpdateEulaShow
Result errorSystemUpdateEulaShow(SetRegion RegionCode, const ErrorEulaData *eula)
Launches the applet for displaying the system-update EULA.
ErrorApplicationArg::errorNumber
u32 errorNumber
Raw decimal error number which is displayed in the dialog.
Definition: error.h:110
errorSystemShow
Result errorSystemShow(ErrorSystemConfig *c)
Launches the applet with the specified config.
ErrorRecordArg::errorCode
ErrorCode errorCode
ErrorCode
Definition: error.h:88
ErrorCommonHeader::resultFlag
u8 resultFlag
ErrorCommonArg: When clear, errorCode is used, otherwise the applet generates the error-code from res...
Definition: error.h:51
ErrorContextType_LocalContentShare
@ ErrorContextType_LocalContentShare
LocalContentShare.
Definition: error.h:34
ErrorApplicationArg::languageCode
u64 languageCode
See set.h.
Definition: error.h:111
u8
uint8_t u8
8-bit unsigned integer.
Definition: types.h:19
errorCodeCreateResult
static ErrorCode errorCodeCreateResult(Result res)
Creates an ErrorCode with the input Result.
Definition: error.h:134
ErrorSystemArg::languageCode
u64 languageCode
See set.h.
Definition: error.h:96
ErrorContextType
ErrorContextType
Error type for ErrorContext.type.
Definition: error.h:29
ErrorEulaArg::regionCode
SetRegion regionCode
SetRegion
Definition: error.h:77
errorEulaShow
Result errorEulaShow(SetRegion RegionCode)
Launches the applet for displaying the EULA.
ErrorPctlArg::res
Result res
Result.
Definition: error.h:65
errorResultBacktraceCreate
Result errorResultBacktraceCreate(ErrorResultBacktrace *backtrace, s32 count, const Result *entries)
Creates an ErrorResultBacktrace struct.
s32
int32_t s32
32-bit signed integer.
Definition: types.h:27
errorApplicationSetLanguageCode
static void errorApplicationSetLanguageCode(ErrorApplicationConfig *c, u64 LanguageCode)
Sets the LanguageCode.
Definition: error.h:310
ErrorCommonHeader
Common header for the start of the arg storage.
Definition: error.h:46
errorSystemSetContext
void errorSystemSetContext(ErrorSystemConfig *c, const ErrorContext *ctx)
Sets the ErrorContext.
ErrorContextType_FileSystem
@ ErrorContextType_FileSystem
FileSystem.
Definition: error.h:32
errorCodeIsValid
static bool errorCodeIsValid(ErrorCode errorCode)
Checks whether the input ErrorCode is valid.
Definition: error.h:149
ErrorContextType_None
@ ErrorContextType_None
None.
Definition: error.h:30
R_DESCRIPTION
#define R_DESCRIPTION(res)
Returns the description of a result code.
Definition: result.h:16
ErrorApplicationArg
ApplicationErrorArg.
Definition: error.h:108
ErrorContext::type
u8 type
Type, see ErrorContextType.
Definition: error.h:39
ErrorSystemArg::errorCode
ErrorCode errorCode
ErrorCode
Definition: error.h:95
ErrorCommonHeader::contextFlag2
u8 contextFlag2
Similar to contextFlag except for ErrorCommonArg, indicating ErrorContext is used.
Definition: error.h:52
ErrorType_Normal
@ ErrorType_Normal
Normal.
Definition: error.h:13
errorApplicationShow
Result errorApplicationShow(ErrorApplicationConfig *c)
Launches the applet with the specified config.
ErrorContextType_WebMediaPlayer
@ ErrorContextType_WebMediaPlayer
WebMediaPlayer.
Definition: error.h:33
ErrorEulaArg
Error arg data for EULA.
Definition: error.h:75
ErrorRecordArg
Error arg data for Record.
Definition: error.h:86
ErrorType_System
@ ErrorType_System
System.
Definition: error.h:14
u32
uint32_t u32
32-bit unsigned integer.
Definition: types.h:21
ErrorApplicationArg::hdr
ErrorCommonHeader hdr
Common header.
Definition: error.h:109
ErrorCommonHeader::jumpFlag
u8 jumpFlag
When clear, this indicates WithoutJump.
Definition: error.h:48
ErrorType
ErrorType
Error type for ErrorCommonHeader.type.
Definition: error.h:12
errorResultShow
Result errorResultShow(Result res, bool jumpFlag, const ErrorContext *ctx)
Launches the applet for displaying the specified Result.
errorApplicationCreate
Result errorApplicationCreate(ErrorApplicationConfig *c, const char *dialog_message, const char *fullscreen_message)
Creates an ErrorApplicationConfig struct.
u64
uint64_t u64
64-bit unsigned integer.
Definition: types.h:22
errorResultBacktraceShow
Result errorResultBacktraceShow(Result res, const ErrorResultBacktrace *backtrace)
Launches the applet for ErrorResultBacktrace.
ErrorCommonArg::hdr
ErrorCommonHeader hdr
Common header.
Definition: error.h:57
ErrorResultBacktrace
ResultBacktrace.
Definition: error.h:69
ErrorCommonHeader::contextFlag
u8 contextFlag
When set with ErrorType_Normal, indicates that an additional storage is pushed for ErrorResultBacktra...
Definition: error.h:50
errorCodeShow
Result errorCodeShow(ErrorCode errorCode, bool jumpFlag, const ErrorContext *ctx)
Launches the applet for displaying the specified ErrorCode.
Result
u32 Result
Function error code result type.
Definition: types.h:44
ErrorType_Pctl
@ ErrorType_Pctl
Parental Controls.
Definition: error.h:17
ErrorType_Application
@ ErrorType_Application
Application.
Definition: error.h:15
ErrorPctlArg::hdr
ErrorCommonHeader hdr
Common header.
Definition: error.h:64
ErrorContext::res
Result res
Result.
Definition: error.h:42
ErrorCode::low
u32 low
The module portion of the error, normally this should be set to module + 2000.
Definition: error.h:24
ErrorSystemConfig::ctx
ErrorContext ctx
Optional error context.
Definition: error.h:104
ErrorApplicationConfig
Error application config.
Definition: error.h:117
errorResultRecordShow
static Result errorResultRecordShow(Result res, u64 timestamp)
Launches the applet for displaying an error full-screen, using the specified Result and timestamp.
Definition: error.h:223
ErrorRecordArg::hdr
ErrorCommonHeader hdr
Common header.
Definition: error.h:87
ErrorContextType_Http
@ ErrorContextType_Http
Http.
Definition: error.h:31
ErrorCommonHeader::type
u8 type
Type, see ErrorType.
Definition: error.h:47
ErrorType_Record
@ ErrorType_Record
Record.
Definition: error.h:18
ErrorRecordArg::timestamp
u64 timestamp
POSIX timestamp.
Definition: error.h:89
ErrorEulaArg::hdr
ErrorCommonHeader hdr
Common header.
Definition: error.h:76
ErrorCommonArg
Common error arg data.
Definition: error.h:56
ErrorSystemConfig::arg
ErrorSystemArg arg
Arg data.
Definition: error.h:103
ErrorCommonArg::errorCode
ErrorCode errorCode
ErrorCode
Definition: error.h:58
ErrorEulaData
Additional input storage data for errorSystemUpdateEulaShow.
Definition: error.h:81
ErrorCommonArg::res
Result res
Result.
Definition: error.h:59
errorApplicationSetNumber
static void errorApplicationSetNumber(ErrorApplicationConfig *c, u32 errorNumber)
Sets the error code number.
Definition: error.h:301
PACKED
#define PACKED
Packs a struct so that it won't include padding bytes.
Definition: types.h:63
ErrorContext
Error context.
Definition: error.h:38
ErrorResultBacktrace::count
s32 count
Total entries in the backtrace array.
Definition: error.h:70
SetRegion
SetRegion
Region codes.
Definition: set.h:62
ErrorSystemConfig
Error system config.
Definition: error.h:102
errorCodeRecordShow
Result errorCodeRecordShow(ErrorCode errorCode, u64 timestamp)
Launches the applet for displaying an error full-screen, using the specified ErrorCode and timestamp.
ErrorCode
Stores error-codes which are displayed as XXXX-XXXX, low for the former and desc for the latter.
Definition: error.h:23
ErrorPctlArg
Error arg data for certain errors with module PCTL.
Definition: error.h:63
errorSystemCreate
Result errorSystemCreate(ErrorSystemConfig *c, const char *dialog_message, const char *fullscreen_message)
Creates an ErrorSystemConfig struct.
errorSystemSetLanguageCode
static void errorSystemSetLanguageCode(ErrorSystemConfig *c, u64 LanguageCode)
Sets the LanguageCode.
Definition: error.h:267
ErrorType_SystemUpdateEula
@ ErrorType_SystemUpdateEula
SystemUpdateEula.
Definition: error.h:19
ErrorSystemArg::hdr
ErrorCommonHeader hdr
Common header.
Definition: error.h:94
ErrorApplicationConfig::arg
ErrorApplicationArg arg
Arg data.
Definition: error.h:118
errorSystemSetCode
static void errorSystemSetCode(ErrorSystemConfig *c, ErrorCode errorCode)
Sets the error code.
Definition: error.h:249
ErrorCode::desc
u32 desc
The error description.
Definition: error.h:25
errorCodeCreate
static ErrorCode errorCodeCreate(u32 low, u32 desc)
Creates an ErrorCode.
Definition: error.h:126
errorSystemSetResult
static void errorSystemSetResult(ErrorSystemConfig *c, Result res)
Sets the error code, using the input Result.
Definition: error.h:258