diff options
Diffstat (limited to 'edify/expr.cpp')
-rw-r--r-- | edify/expr.cpp | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/edify/expr.cpp b/edify/expr.cpp index 54ab3325c..6823b7339 100644 --- a/edify/expr.cpp +++ b/edify/expr.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "expr.h" +#include "edify/expr.h" #include <stdarg.h> #include <stdio.h> @@ -31,6 +31,8 @@ #include <android-base/stringprintf.h> #include <android-base/strings.h> +#include "otautil/error_code.h" + // Functions should: // // - return a malloc()'d string @@ -112,9 +114,9 @@ Value* IfElseFn(const char* name, State* state, const std::vector<std::unique_pt Value* AbortFn(const char* name, State* state, const std::vector<std::unique_ptr<Expr>>& argv) { std::string msg; if (!argv.empty() && Evaluate(state, argv[0], &msg)) { - state->errmsg = msg; + state->errmsg += msg; } else { - state->errmsg = "called abort()"; + state->errmsg += "called abort()"; } return nullptr; } @@ -408,16 +410,16 @@ Value* ErrorAbort(State* state, const char* format, ...) { } Value* ErrorAbort(State* state, CauseCode cause_code, const char* format, ...) { - va_list ap; - va_start(ap, format); - android::base::StringAppendV(&state->errmsg, format, ap); - va_end(ap); - state->cause_code = cause_code; - return nullptr; -} - -State::State(const std::string& script, void* cookie) : - script(script), - cookie(cookie) { + std::string err_message; + va_list ap; + va_start(ap, format); + android::base::StringAppendV(&err_message, format, ap); + va_end(ap); + // Ensure that there's exactly one line break at the end of the error message. + state->errmsg = android::base::Trim(err_message) + "\n"; + state->cause_code = cause_code; + return nullptr; } +State::State(const std::string& script, void* cookie) + : script(script), cookie(cookie), error_code(kNoError), cause_code(kNoCause) {} |