Skip to content

Commit

Permalink
feat: add compilation error for export_as with full
Browse files Browse the repository at this point in the history
  • Loading branch information
coroiu committed Nov 13, 2024
1 parent 5cfa4d0 commit 7b627cb
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 4 deletions.
87 changes: 85 additions & 2 deletions Cargo.lock

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

11 changes: 9 additions & 2 deletions crates/bitwarden-error-macro/src/full/attribute.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
use darling::Error;
use quote::quote;

pub(crate) fn bitwarden_error_full(
input: &syn::DeriveInput,
_type_identifier: &proc_macro2::Ident,
_export_as_identifier: &proc_macro2::Ident,
type_identifier: &proc_macro2::Ident,
export_as_identifier: &proc_macro2::Ident,
) -> proc_macro::TokenStream {
if type_identifier != export_as_identifier {
return Error::custom("`bitwarden_error(full)` does not currently support `export_as`")
.write_errors()
.into();
}

let wasm_attributes = cfg!(feature = "wasm").then(|| {
quote! {
#[derive(tsify_next::Tsify)]
Expand Down
1 change: 1 addition & 0 deletions crates/bitwarden-error/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ workspace = true
[dev-dependencies]
js-sys = "0.3.72"
serde.workspace = true
trybuild = "1.0.101"
tsify-next = "0.5.4"
wasm-bindgen-test = "0.3.45"
7 changes: 7 additions & 0 deletions crates/bitwarden-error/tests/compilation_tests/full.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use bitwarden_error::prelude::*;

/// Full errors do not support changing the name of the error in the generated JS
#[bitwarden_error(full, export_as = "SomeOtherError")]
struct SomeError;

fn main() {}
7 changes: 7 additions & 0 deletions crates/bitwarden-error/tests/compilation_tests/full.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
error: `bitwarden_error(full)` does not currently support `export_as`
--> tests/compilation_tests/full.rs:4:1
|
4 | #[bitwarden_error(full, export_as = "SomeOtherError")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the attribute macro `bitwarden_error` (in Nightly builds, run with -Z macro-backtrace for more info)
6 changes: 6 additions & 0 deletions crates/bitwarden-error/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
mod basic;
mod flat;
mod full;

#[test]
fn compilation_tests() {
let t = trybuild::TestCases::new();
t.compile_fail("tests/compilation_tests/*.rs");
}

0 comments on commit 7b627cb

Please sign in to comment.