1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-15 04:15:44 +03:00

Merge pull request #7635 from mikeller/make_errors_spottable

Make errors in 'diff' / 'dump' easier to spot and parse.
This commit is contained in:
Michael Keller 2019-02-23 13:44:20 +13:00 committed by GitHub
commit e22e7e1637
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -391,19 +391,23 @@ static void cliPrintLinef(const char *format, ...)
cliPrintLinefeed(); cliPrintLinefeed();
} }
static void cliPrintErrorLinef(const char *format, ...) static void cliPrintError(const char *format, ...)
{ {
cliPrint("###"); cliPrint("###ERROR: ");
va_list va; va_list va;
va_start(va, format); va_start(va, format);
cliPrintfva(format, va); cliPrintfva(format, va);
va_end(va); va_end(va);
cliPrintLine("###"); cliPrint("###");
} }
static void cliPrintCorruptMessage(int value) static void cliPrintErrorLinef(const char *format, ...)
{ {
cliPrintf("%d ###CORRUPTED CONFIG###", value); va_list va;
va_start(va, format);
cliPrintError(format, va);
va_end(va);
cliPrintLinefeed();
} }
static void getMinMax(const clivalue_t *var, int *min, int *max) static void getMinMax(const clivalue_t *var, int *min, int *max)
@ -480,29 +484,26 @@ static void printValuePointer(const clivalue_t *var, const void *valuePointer, b
break; break;
} }
bool valueIsCorrupted = false;
switch (var->type & VALUE_MODE_MASK) { switch (var->type & VALUE_MODE_MASK) {
case MODE_DIRECT: case MODE_DIRECT:
if ((var->type & VALUE_TYPE_MASK) == VAR_UINT32) { if ((var->type & VALUE_TYPE_MASK) == VAR_UINT32) {
cliPrintf("%d", value);
if ((uint32_t) value > var->config.u32Max) { if ((uint32_t) value > var->config.u32Max) {
cliPrintCorruptMessage(value); valueIsCorrupted = true;
} else { } else if (full) {
cliPrintf("%d", value); cliPrintf(" 0 %d", var->config.u32Max);
if (full) {
cliPrintf(" 0 %d", var->config.u32Max);
}
} }
} else { } else {
int min; int min;
int max; int max;
getMinMax(var, &min, &max); getMinMax(var, &min, &max);
cliPrintf("%d", value);
if ((value < min) || (value > max)) { if ((value < min) || (value > max)) {
cliPrintCorruptMessage(value); valueIsCorrupted = true;
} else { } else if (full) {
cliPrintf("%d", value); cliPrintf(" %d %d", min, max);
if (full) {
cliPrintf(" %d %d", min, max);
}
} }
} }
break; break;
@ -510,7 +511,7 @@ static void printValuePointer(const clivalue_t *var, const void *valuePointer, b
if (value < lookupTables[var->config.lookup.tableIndex].valueCount) { if (value < lookupTables[var->config.lookup.tableIndex].valueCount) {
cliPrint(lookupTables[var->config.lookup.tableIndex].values[value]); cliPrint(lookupTables[var->config.lookup.tableIndex].values[value]);
} else { } else {
cliPrintCorruptMessage(value); valueIsCorrupted = true;
} }
break; break;
case MODE_BITSET: case MODE_BITSET:
@ -520,6 +521,11 @@ static void printValuePointer(const clivalue_t *var, const void *valuePointer, b
cliPrintf("OFF"); cliPrintf("OFF");
} }
} }
if (valueIsCorrupted) {
cliPrintLinefeed();
cliPrintError("CORRUPTED CONFIG: %s = %d", var->name, value);
}
} }
} }
@ -3831,6 +3837,7 @@ STATIC_UNIT_TESTED void cliGet(char *cmdline)
} }
cliPrintVarRange(val); cliPrintVarRange(val);
cliPrintVarDefault(val); cliPrintVarDefault(val);
matchedCommands++; matchedCommands++;
} }
} }
@ -5470,10 +5477,11 @@ void cliProcess(void)
break; break;
} }
} }
if (cmd < cmdTable + ARRAYLEN(cmdTable)) if (cmd < cmdTable + ARRAYLEN(cmdTable)) {
cmd->func(options); cmd->func(options);
else } else {
cliPrint("Unknown command, try 'help'"); cliPrintError("UNKNOWN COMMAND, TRY 'HELP'");
}
bufferIndex = 0; bufferIndex = 0;
} }