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

Ensure services with no operations generate valid Rust #2351

Closed
wants to merge 11 commits into from

Conversation

hlbarber
Copy link
Contributor

Description

  • Add test coverage for a service with no operations
  • Correct the service builder code to allow for this

@@ -216,15 +218,14 @@ class ServerServiceGeneratorV2(
pub fn build(self) -> Result<$serviceName<#{SmithyHttpServer}::routing::Route<$builderBodyGenericTypeName>>, MissingOperationsError>
{
let router = {
use #{SmithyHttpServer}::operation::OperationShape;
##[allow(unused_mut)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add this conditionally on the fact that we know there are no operations?

Copy link
Contributor Author

@hlbarber hlbarber Feb 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is something we generally do (perhaps it should be). Will do it in this case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Loosening lints in all cases can lead to bugs going undetected (because a legitimate lint doesn't trigger). If it's easy enough to be precise, I think we should be.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's easy enough to be precise, I think we should be.

+1 to this. I don't think we should bend over backwards to have lints be as tight as possible, but if it's easy I'd go for it.

val expectMessageVariableName = "unexpected_error_msg"
val expectMessage = "this should never panic since we are supposed to check beforehand that a handler has been registered for this operation; please file a bug report under https://github.com/awslabs/smithy-rs/issues"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We used a variable there to avoid having multiple copies of the same string in the final binary artefact 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, I'd be surprised if it didn't deduplicate them. But I'll put a conditional #[allow(unused_variables)] instead.

@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

"""
if self.$fieldName.is_none() {
use #{SmithyHttpServer}::operation::OperationShape;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this needed? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The line below uses OperationShape::NAME. It was previously imported below which was unused in the no operation case.

Comment on lines 210 to 216
var missingOperationsUnusedMut = ""
var unusedExpected = ""
if (operations.isEmpty()) {
missingOperationsUnusedMut = "##[allow(unused_mut)]"
unusedExpected = "##[allow(unused_variables)]"
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can use Attribute.AllowUnusedMut/AllowUnusedVariables.render(writer) for these.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

@hlbarber
Copy link
Contributor Author

Following the decision made in #1369 we should NOT generate code for this Smithy class of models and instead throw an exception.

@hlbarber hlbarber closed this Feb 14, 2023
@hlbarber hlbarber deleted the harryb/empty-service-check branch June 14, 2023 11:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
server Rust server SDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants