EncodingContext: Forward the backtrace of stored errors.

This makes error messages from command buffers more useful because they
keep the whole stack trace instead of just showing that the error was
created in the CommandBuffer::Finish call.

Bug: dawn:632
Change-Id: I23e66045c3caa1ad086003a04eed78c40aefc562
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/49885
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Stephen White <senorblanco@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
diff --git a/src/dawn_native/EncodingContext.cpp b/src/dawn_native/EncodingContext.cpp
index acdecd7..1752f6c 100644
--- a/src/dawn_native/EncodingContext.cpp
+++ b/src/dawn_native/EncodingContext.cpp
@@ -53,18 +53,17 @@
         }
     }
 
-    void EncodingContext::HandleError(InternalErrorType type, const char* message) {
+    void EncodingContext::HandleError(std::unique_ptr<ErrorData> error) {
         if (!IsFinished()) {
             // Encoding should only generate validation errors.
-            ASSERT(type == InternalErrorType::Validation);
+            ASSERT(error->GetType() == InternalErrorType::Validation);
             // If the encoding context is not finished, errors are deferred until
             // Finish() is called.
-            if (!mGotError) {
-                mGotError = true;
-                mErrorMessage = message;
+            if (mError == nullptr) {
+                mError = std::move(error);
             }
         } else {
-            mDevice->HandleError(type, message);
+            mDevice->HandleError(error->GetType(), error->GetMessage().c_str());
         }
     }
 
@@ -129,8 +128,8 @@
         mCurrentEncoder = nullptr;
         mTopLevelEncoder = nullptr;
 
-        if (mGotError) {
-            return DAWN_VALIDATION_ERROR(mErrorMessage);
+        if (mError != nullptr) {
+            return std::move(mError);
         }
         if (currentEncoder != topLevelEncoder) {
             return DAWN_VALIDATION_ERROR("Command buffer recording ended mid-pass");