Skip to content

Commit

Permalink
Fix error type name "Error" (#93)
Browse files Browse the repository at this point in the history
Signed-off-by: Kristupas Antanavičius <[email protected]>
  • Loading branch information
arg0d authored Oct 11, 2024
1 parent f68639f commit 1913e7a
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 4 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bindgen/templates/BigEndianStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Big endian streams are not yet available in dotnet :'(
// https://github.com/dotnet/runtime/issues/26904

class StreamUnderflowException: Exception {
class StreamUnderflowException: System.Exception {
public StreamUnderflowException() {
}
}
Expand Down
2 changes: 1 addition & 1 deletion bindgen/templates/CallbackInterfaceTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private static int INSTANCE_FUNC(ulong handle, uint method, IntPtr argsData, int
outBuf = {{ method_name }}(cb, RustBuffer.MemoryStream(argsData, argsLength));
return UniffiCallbackResponseCode.SUCCESS;
{%- endmatch %}
} catch (Exception e) {
} catch (System.Exception e) {
// Unexpected error
try {
// Try to serialize the error into a string
Expand Down
4 changes: 2 additions & 2 deletions bindgen/templates/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public bool IsPanic() {
}

// Base class for all uniffi exceptions
{{ config.access_modifier() }} class UniffiException: Exception {
{{ config.access_modifier() }} class UniffiException: System.Exception {
public UniffiException(): base() {}
public UniffiException(string message): base(message) {}
}
Expand Down Expand Up @@ -61,7 +61,7 @@ public UniffiContractChecksumException(string message): base(message) {
}

// Each top-level error class has a companion object that can lift the error from the call status's rust buffer
interface CallStatusErrorHandler<E> where E: Exception {
interface CallStatusErrorHandler<E> where E: System.Exception {
E Lift(RustBuffer error_buf);
}

Expand Down
16 changes: 16 additions & 0 deletions dotnet-tests/UniffiCS.BindingTests/TestRegressions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

using uniffi.issue_76;

namespace UniffiCS.BindingTests;

public class TestRegressions
{
[Fact]
public void TestIssue76()
{
Assert.Throws<Exception.Example>(() => Issue76Methods.AlwaysError());
}
}
1 change: 1 addition & 0 deletions fixtures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ crate-type = ["cdylib", "lib"]

[dependencies]
global-methods-class-name = { path = "global-methods-class-name" }
issue-76 = { path = "regressions/issue-76" }
null-to-empty-string = { path = "null-to-empty-string" }
uniffi-cs-custom-types-builtin = { path = "custom-types-builtin" }
uniffi-cs-disposable-fixture = { path = "disposable" }
Expand Down
17 changes: 17 additions & 0 deletions fixtures/regressions/issue-76/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "issue-76"
version = "1.0.0"
edition = "2021"
publish = false

[lib]
crate-type = ["lib", "cdylib"]
name = "issue_76"

[dependencies]
uniffi = {path = "../../../3rd-party/uniffi-rs/uniffi", features=["build"]}
uniffi_macros = {path = "../../../3rd-party/uniffi-rs/uniffi_macros"}
thiserror = "1.0"

[build-dependencies]
uniffi = {path = "../../../3rd-party/uniffi-rs/uniffi", features=["bindgen-tests"]}
3 changes: 3 additions & 0 deletions fixtures/regressions/issue-76/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# https://github.com/NordSecurity/uniffi-bindgen-cs/issues/76

`Error` is translated into `Exception`, and causes ambiguous type references between `System.Exception` and `Exception`.
16 changes: 16 additions & 0 deletions fixtures/regressions/issue-76/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#[derive(Debug, thiserror::Error, uniffi::Error)]
pub enum Error {
#[error("Example")]
Example,
}

#[uniffi::export]
pub fn always_error() -> Result<(), Error> {
Err(Error::Example)
}

uniffi::setup_scaffolding!();
1 change: 1 addition & 0 deletions fixtures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ mod uniffi_fixtures {
uniffi_cs_disposable::uniffi_reexport_scaffolding!();
uniffi_cs_optional_parameters::uniffi_reexport_scaffolding!();
stringify::uniffi_reexport_scaffolding!();
issue_76::uniffi_reexport_scaffolding!();
}

0 comments on commit 1913e7a

Please sign in to comment.