aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTianjie Xu2016-04-30 13:49:59 -0500
committerTianjie Xu2016-05-20 15:56:53 -0500
commit162558382b768a4120b3e41090a4c7b53f11469a (patch)
tree7e0d268233fc6bea07a361cf6913fc3a5e524063 /edify/expr.cpp
parentdd874b1c87eb04f28db0db2629df0adde568a74c (diff)
downloadplatform-bootable-recovery-162558382b768a4120b3e41090a4c7b53f11469a.tar.gz
platform-bootable-recovery-162558382b768a4120b3e41090a4c7b53f11469a.tar.xz
platform-bootable-recovery-162558382b768a4120b3e41090a4c7b53f11469a.zip
Allow recovery to return error codes
Write error code, cause code, and retry count into last_install. So we can have more information about the reason of a failed OTA. Example of new last_install: @/cache/recovery/block.map package name 0 install result retry: 1 retry count (new) error: 30 error code (new) cause: 12 error cause (new) Details in: go/android-ota-errorcode Bug: 28471955 Change-Id: I00e7153c821e7355c1be81a86c7f228108f3dc37
Diffstat (limited to 'edify/expr.cpp')
-rw-r--r--edify/expr.cpp39
1 files changed, 29 insertions, 10 deletions
diff --git a/edify/expr.cpp b/edify/expr.cpp
index cd1e0872..cc14fbe9 100644
--- a/edify/expr.cpp
+++ b/edify/expr.cpp
@@ -21,6 +21,11 @@
21#include <stdarg.h> 21#include <stdarg.h>
22#include <unistd.h> 22#include <unistd.h>
23 23
24#include <string>
25
26#include <android-base/stringprintf.h>
27#include <android-base/strings.h>
28
24#include "expr.h" 29#include "expr.h"
25 30
26// Functions should: 31// Functions should:
@@ -36,7 +41,7 @@ char* Evaluate(State* state, Expr* expr) {
36 Value* v = expr->fn(expr->name, state, expr->argc, expr->argv); 41 Value* v = expr->fn(expr->name, state, expr->argc, expr->argv);
37 if (v == NULL) return NULL; 42 if (v == NULL) return NULL;
38 if (v->type != VAL_STRING) { 43 if (v->type != VAL_STRING) {
39 ErrorAbort(state, "expecting string, got value type %d", v->type); 44 ErrorAbort(state, kArgsParsingFailure, "expecting string, got value type %d", v->type);
40 FreeValue(v); 45 FreeValue(v);
41 return NULL; 46 return NULL;
42 } 47 }
@@ -493,15 +498,29 @@ Value** ReadValueVarArgs(State* state, int argc, Expr* argv[]) {
493 return args; 498 return args;
494} 499}
495 500
501static void ErrorAbortV(State* state, const char* format, va_list ap) {
502 std::string buffer;
503 android::base::StringAppendV(&buffer, format, ap);
504 free(state->errmsg);
505 state->errmsg = strdup(buffer.c_str());
506 return;
507}
508
496// Use printf-style arguments to compose an error message to put into 509// Use printf-style arguments to compose an error message to put into
497// *state. Returns NULL. 510// *state. Returns nullptr.
498Value* ErrorAbort(State* state, const char* format, ...) { 511Value* ErrorAbort(State* state, const char* format, ...) {
499 char* buffer = reinterpret_cast<char*>(malloc(4096)); 512 va_list ap;
500 va_list v; 513 va_start(ap, format);
501 va_start(v, format); 514 ErrorAbortV(state, format, ap);
502 vsnprintf(buffer, 4096, format, v); 515 va_end(ap);
503 va_end(v); 516 return nullptr;
504 free(state->errmsg); 517}
505 state->errmsg = buffer; 518
506 return NULL; 519Value* ErrorAbort(State* state, CauseCode cause_code, const char* format, ...) {
520 va_list ap;
521 va_start(ap, format);
522 ErrorAbortV(state, format, ap);
523 va_end(ap);
524 state->cause_code = cause_code;
525 return nullptr;
507} 526}