Skip to content

Rust style guide: minor adjustments to documentation guidelines, panic states#769

Open
neuronull wants to merge 4 commits intomainfrom
neuronull/pm-31660/rust-style-guide-documenting-code-and-mutex-panics
Open

Rust style guide: minor adjustments to documentation guidelines, panic states#769
neuronull wants to merge 4 commits intomainfrom
neuronull/pm-31660/rust-style-guide-documenting-code-and-mutex-panics

Conversation

@neuronull
Copy link
Contributor

🎟️ Tracking

https://bitwarden.atlassian.net/browse/PM-31660

📔 Objective

During code review on one of my PRs in clients repo, @quexten astutely flagged some discrepancies of my code to the style guide. While I adjusted some of my code, I did feel that some of the contributing docs' guidelines could use a little more color, given the nature of it covering all of our repositories, which includes the sdk-internal library, and desktop_native in clients.

Very open to discussion on the topics and adjustments to the examples etc.

📸 Screenshots

@github-actions
Copy link
Contributor

github-actions bot commented Feb 13, 2026

Logo
Checkmarx One – Scan Summary & Detailsfd55980b-efd4-4ed4-bb4c-70cef2ce9ad0

Great job! No new security vulnerabilities introduced in this pull request

@neuronull
Copy link
Contributor Author

The CI failure in Lint seems to also be failing on main. But when I run npm ci locally, I don't see an error from prettier.

@neuronull neuronull marked this pull request as ready for review February 13, 2026 20:38
@neuronull neuronull requested a review from a team as a code owner February 13, 2026 20:38
quexten
quexten previously approved these changes Feb 17, 2026
Copy link
Contributor

@quexten quexten left a comment

Choose a reason for hiding this comment

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

Not a codeowner, but changes look good from my perspective.

@neuronull neuronull requested a review from Hinton February 19, 2026 17:56
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Mar 2, 2026

Deploying contributing-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 96174cd
Status:🚫  Build failed.

View logs

jprusik
jprusik previously approved these changes Mar 3, 2026
was violated. This provides highly readable code and crash logs. For example:

```rust
let some_object = self.shared_object.lock().expect("Mutex not to be poisoned.");
Copy link
Member

Choose a reason for hiding this comment

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

This does not follow the recommended pattern, https://doc.rust-lang.org/std/error/index.html#common-message-styles

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could you specify which aspect does not fit the recommended pattern?

I believe it most closely matches the third one.

In the “expect as precondition” style, we would instead describe the reason we expect the Result should be Ok. With this style we would prefer to write:

let path = std::env::var("IMPORTANT_PATH")
.expect("env variable IMPORTANT_PATH should be set by wrapper_script.sh");

If you still sense that explicit argument documentation would be helpful, this could be a hint to
extract the arguments into a separate struct to improve clarity and enforce type safety.

Let's say `sum_positive_integers()` is now a library function in our utils module.
Copy link
Member

Choose a reason for hiding this comment

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

This only applies to the good example. Skip?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, this is meant to be a reference to the function of the same name in the "Functions" section. I think if the "bad" example below is renamed to also be called sum_positive_integers, it would encapsulate the message for this section.

Perhaps having a "good" and "bad" section in "Functions" above (copying the sum() bad example up there) would help. So then we have a good and bad example for both sections.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did that in 96174cd

…d-mutex-panics' of github.com:bitwarden/contributing-docs into neuronull/pm-31660/rust-style-guide-documenting-code-and-mutex-panics
@neuronull neuronull dismissed stale reviews from jprusik and quexten via 96174cd March 4, 2026 17:47
@neuronull neuronull requested a review from Hinton March 4, 2026 17:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants