Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constrained shapes that reach @sensitive shapes don't implement Debug #2582

Closed
david-perez opened this issue Apr 14, 2023 · 0 comments · Fixed by #2585
Closed

Constrained shapes that reach @sensitive shapes don't implement Debug #2582

david-perez opened this issue Apr 14, 2023 · 0 comments · Fixed by #2585
Labels
bug Something isn't working server Rust server SDK

Comments

@david-perez
Copy link
Contributor

Minimal reproducer:

$version: "2.0"

namespace com.amazonaws.simple

use aws.protocols#restJson1
use smithy.framework#ValidationException

@restJson1
service SimpleService {
    operations: [
        Operation
    ]
}

@http(uri: "/operation", method: "POST")
operation Operation {
    input: OperationInputOutput
    output: OperationInputOutput
    errors: [ValidationException]
}

structure OperationInputOutput {
    constrainedList: ConstrainedList
}

@length(min: 69)
list ConstrainedList {
    member: SensitiveStructure
}

@sensitive
structure SensitiveStructure {
    password: String
}

Generates:

#[allow(missing_docs)] // documentation missing in model
#[derive(
    std::clone::Clone, std::cmp::Eq, std::cmp::PartialEq, std::fmt::Debug, std::hash::Hash,
)]
pub struct OperationInput {
    #[allow(missing_docs)] // documentation missing in model
    #[doc(hidden)]
    pub constrained_list: std::option::Option<crate::model::ConstrainedList>,
}

...

#[derive(std::clone::Clone, std::cmp::Eq, std::cmp::PartialEq, std::hash::Hash)]
pub struct ConstrainedList(pub(crate) std::vec::Vec<crate::model::SensitiveStructure>);

...

#[allow(missing_docs)] // documentation missing in model
#[derive(std::clone::Clone, std::cmp::Eq, std::cmp::PartialEq, std::hash::Hash)]
pub struct SensitiveStructure {
    #[allow(missing_docs)] // documentation missing in model
    #[doc(hidden)]
    pub password: std::option::Option<std::string::String>,
}

...

impl std::fmt::Debug for SensitiveStructure {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        let mut formatter = f.debug_struct("SensitiveStructure");
        formatter.field("password", &"*** Sensitive Data Redacted ***");
        formatter.finish()
    }
}

And so we get:

error[E0277]: `ConstrainedList` doesn't implement `std::fmt::Debug`
 --> simple/rust-server-codegen/src/input.rs:9:5
  |
4 |     std::clone::Clone, std::cmp::Eq, std::cmp::PartialEq, std::fmt::Debug, std::hash::Hash,
  |                                                           --------------- in this derive macro expansion
...
9 |     pub constrained_list: std::option::Option<crate::model::ConstrainedList>,
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `ConstrainedList` cannot be formatted using `{:?}`

The mistake is around here:

https://github.com/awslabs/smithy-rs/blob/35f2f27a8380a1310c264a386e162cd9f2180137/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ConstrainedShapeSymbolMetadataProvider.kt#L46-L48

Here, we're not adding #[derive(Debug)] on the constrained shape ConstrainedList because containerDefaultMetadata(shape, model).derives does not include Debug: indeed, SensitiveStructure does not #[derive(Debug)] because it implements Debug manually.

@david-perez david-perez added bug Something isn't working server Rust server SDK labels Apr 14, 2023
david-perez added a commit that referenced this issue Apr 17, 2023
Constrained shapes should always be able to `#[derive(Debug)]`.

Fixes #2582.
unexge pushed a commit that referenced this issue Apr 24, 2023
)

Constrained shapes should always be able to `#[derive(Debug)]`.

Fixes #2582.

## Testing

The modified integration test fails without this patch applied.

## Checklist
<!--- If a checkbox below is not applicable, then please DELETE it
rather than leaving it unchecked -->
- [x] I have updated `CHANGELOG.next.toml` if I made changes to the
smithy-rs codegen or runtime crates

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._

Co-authored-by: Matteo Bigoi <[email protected]>
rcoh pushed a commit that referenced this issue Apr 24, 2023
)

Constrained shapes should always be able to `#[derive(Debug)]`.

Fixes #2582.

## Testing

The modified integration test fails without this patch applied.

## Checklist
<!--- If a checkbox below is not applicable, then please DELETE it
rather than leaving it unchecked -->
- [x] I have updated `CHANGELOG.next.toml` if I made changes to the
smithy-rs codegen or runtime crates

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._

Co-authored-by: Matteo Bigoi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working server Rust server SDK
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant