Kotlin: Throwing `WebGpuException` instead of `DawnException` for synchronous methods.
Additional Fixes:
- Fixes a typo in api_kotlin_exceptions.kt template
- Updates existing test cases to expect `WebGpuException`.
BUG: b/460083622
Change-Id: I25bb11af70b3f5ef48aba06ee146ca3be45d95ce
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/273954
Reviewed-by: Jim Blackler <jimblackler@google.com>
Commit-Queue: Mridul Goyal <mridulgoyal@google.com>
diff --git a/generator/templates/art/api_kotlin_exceptions.kt b/generator/templates/art/api_kotlin_exceptions.kt
index 6797e99..64be4e2 100644
--- a/generator/templates/art/api_kotlin_exceptions.kt
+++ b/generator/templates/art/api_kotlin_exceptions.kt
@@ -73,7 +73,7 @@
{% endfor %}
/**
- * Create the execption for the appropriate error type.
+ * Create the exception for the appropriate error type.
* @param type The [{{ kotlin_name(ns.error) }}].
* @param message A human-readable message describing the device loss.
*/
diff --git a/generator/templates/art/methods.cpp b/generator/templates/art/methods.cpp
index 443b969..5780997 100644
--- a/generator/templates/art/methods.cpp
+++ b/generator/templates/art/methods.cpp
@@ -160,9 +160,13 @@
}
{% if method.returns and method.returns.type.name.canonical_case() == 'status' %}
if (result != WGPUStatus_Success) {
- jclass exClass = env->FindClass("androidx/webgpu/DawnException");
- std::string message = "Dawn method failed with status: " + std::to_string(result);
- env->ThrowNew(exClass, message.c_str());
+ jclass exClass = env->FindClass("androidx/webgpu/WebGpuException");
+ jmethodID exConstructor =
+ env->GetMethodID(exClass, "<init>", "(Ljava/lang/String;I)V");
+ std::string message = "Method GPU{% if object %}{{ object.name.CamelCase() + "." }}{% endif %}{{ method.name.camelCase() }} failed.";
+ jstring jmessage = env->NewStringUTF(message.c_str());
+ jobject exception = env->NewObject(exClass, exConstructor, jmessage, result);
+ env->Throw(static_cast<jthrowable>(exception));
return{{ ' 0' if _kotlin_return }};
}
{% endif %}
diff --git a/tools/android/webgpu/src/androidTest/java/androidx/webgpu/BufferTest.kt b/tools/android/webgpu/src/androidTest/java/androidx/webgpu/BufferTest.kt
index 8fe8590..bb9cc83 100644
--- a/tools/android/webgpu/src/androidTest/java/androidx/webgpu/BufferTest.kt
+++ b/tools/android/webgpu/src/androidTest/java/androidx/webgpu/BufferTest.kt
@@ -4,8 +4,6 @@
import androidx.test.filters.SmallTest
import androidx.webgpu.helper.WebGpu
import androidx.webgpu.helper.createWebGpu
-import androidx.webgpu.DawnException
-import androidx.webgpu.ValidationException
import java.nio.ByteBuffer
import java.nio.ByteOrder
import kotlinx.coroutines.runBlocking
@@ -228,7 +226,7 @@
val readByteBuffer =
ByteBuffer.allocateDirect(bufferSize.toInt()).order(ByteOrder.nativeOrder())
- // The testcase will fail in case readMappedRange throws DawnException
+ // The testcase will fail in case readMappedRange throws WebGpuException
buffer.readMappedRange(0, readByteBuffer)
val readByteBufferFloat = readByteBuffer.asFloatBuffer()
val readData = FloatArray(readByteBufferFloat.remaining())
@@ -255,7 +253,7 @@
)
val byteBuffer = ByteBuffer.allocateDirect(16)
- assertThrows(DawnException::class.java) {
+ assertThrows(WebGpuException::class.java) {
buffer.writeMappedRange(0, byteBuffer)
}
}
diff --git a/tools/android/webgpu/src/androidTest/java/androidx/webgpu/SurfaceTest.kt b/tools/android/webgpu/src/androidTest/java/androidx/webgpu/SurfaceTest.kt
index f70ca41..e66bc06 100644
--- a/tools/android/webgpu/src/androidTest/java/androidx/webgpu/SurfaceTest.kt
+++ b/tools/android/webgpu/src/androidTest/java/androidx/webgpu/SurfaceTest.kt
@@ -78,7 +78,7 @@
assertEquals(currentTexture.format, desiredFormat)
assertEquals(currentTexture.height, HEIGHT)
assertEquals(currentTexture.width, WIDTH)
- // The testcase will fail in case present() throws DawnException
+ // The testcase will fail in case present() throws WebGpuException
surface.present()
}