Started reintegrating what used to be called user bugs; they're now called programmer errors. We'll create a much more systematic approach to them. Implemented on macOS.
This commit is contained in:
parent
781a4117a7
commit
b3049b0a1e
|
@ -2,4 +2,5 @@
|
|||
|
||||
libui_sources += [
|
||||
'common/init.c',
|
||||
'common/programmererror.c',
|
||||
]
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
// 12 may 2019
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include "ui.h"
|
||||
#include "uipriv.h"
|
||||
|
||||
static const char *messages[] = {
|
||||
[uiprivProgrammerErrorWrongStructSize] = "wrong size %zu for %s",
|
||||
[uiprivProgrammerErrorIndexOutOfRange] = "index %d out of range in %s()",
|
||||
};
|
||||
|
||||
static void prepareProgrammerError(char *buf, int size, unsigned int which, va_list ap)
|
||||
{
|
||||
int n;
|
||||
|
||||
if (which >= uiprivNumProgrammerErrors) {
|
||||
// TODO
|
||||
}
|
||||
n = vsnprintf(buf, size, messages[which], ap);
|
||||
if (n < 0) {
|
||||
// TODO
|
||||
}
|
||||
if (n >= size) {
|
||||
// TODO
|
||||
buf[size - 4] = '.';
|
||||
buf[size - 3] = '.';
|
||||
buf[size - 2] = '.';
|
||||
buf[size - 1] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
void uiprivProgrammerError(unsigned int which, ...)
|
||||
{
|
||||
va_list ap;
|
||||
char buf[256];
|
||||
|
||||
va_start(ap, which);
|
||||
prepareProgrammerError(buf, 256, which, ap);
|
||||
va_end(ap);
|
||||
uiprivSysProgrammerError(buf);
|
||||
}
|
|
@ -10,6 +10,18 @@ extern int uiprivSysInit(void *options, uiInitError *err);
|
|||
extern int uiprivInitReturnError(uiInitError *err, const char *msg);
|
||||
extern int uiprivInitReturnErrorf(uiInitError *err, const char *msg, ...);
|
||||
|
||||
// programmererror.c
|
||||
enum {
|
||||
uiprivProgrammerErrorWrongStructSize, // arguments: size_t badSize, const char *structName
|
||||
uiprivProgrammerErrorIndexOutOfRange, // arguments: int badIndex, __func__
|
||||
uiprivNumProgrammerErrors,
|
||||
};
|
||||
extern void uiprivProgrammerError(unsigned int which, ...);
|
||||
extern void uiprivSysProgrammerError(const char *msg);
|
||||
#define uiprivProgrammerErrorPrefix "libui programmer error"
|
||||
// TODO add debugging advice?
|
||||
#define uiprivProgrammerErrorAdvice "This likely means you are using libui incorrectly. Check your source code and try again. If you have received this warning in error, contact the libui authors."
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
// 20 april 2019
|
||||
#import <stdlib.h>
|
||||
#import "uipriv_darwin.h"
|
||||
|
||||
@interface uiprivApplication : NSApplication
|
||||
|
@ -97,3 +98,13 @@ void uiQueueMain(void (*f)(void *data), void *data)
|
|||
// the signature of f matches dispatch_function_t
|
||||
dispatch_async_f(dispatch_get_main_queue(), data, f);
|
||||
}
|
||||
|
||||
void uiprivSysProgrammerError(const char *msg)
|
||||
{
|
||||
NSLog(@"*** %s: %s. %s", uiprivProgrammerErrorPrefix, msg, uiprivProgrammerErrorAdvice);
|
||||
// TODO either find an appropriate exception for each message or use a custom exception name
|
||||
[NSException raise:NSInvalidArgumentException
|
||||
format:@"%s: %s", uiprivProgrammerErrorPrefix, msg];
|
||||
// TODO break into the debugger?
|
||||
abort(); // we shouldn't reach here
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue