Skip to content

Deny anyhow #32135

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Deny anyhow #32135

wants to merge 2 commits into from

Conversation

antiguru
Copy link
Member

@antiguru antiguru commented Apr 9, 2025

Deny access to anyhow macros and some types

Deny access to the anyhow macros anyhow and bail, and the Result type. This covers most of our use of anyhow where we're not just passing errors around.

We could also deny anyhow::Error, but that would need us to silence another 1000+ warnings, which I feel has diminishing returns: we're mostly interested to finding places where we construct errors, which are covered by this change. Unfortunately, anyhow allows silent error conversion, meaning any ? operator can convert from an error to anyhow, so we should eventually deny anyhow::Error, too.

In support of MaterializeInc/database-issues#9092

Checklist

  • This PR has adequate test coverage / QA involvement has been duly considered. (trigger-ci for additional test/nightly runs)
  • This PR has an associated up-to-date design doc, is a design doc (template), or is sufficiently small to not require a design.
  • If this PR evolves an existing $T ⇔ Proto$T mapping (possibly in a backwards-incompatible way), then it is tagged with a T-proto label.
  • If this PR will require changes to cloud orchestration or tests, there is a companion cloud PR to account for those changes that is tagged with the release-blocker label (example).
  • If this PR includes major user-facing behavior changes, I have pinged the relevant PM to schedule a changelog post.

antiguru added 2 commits April 9, 2025 10:10
Denies the use of the anyhow `anyhow` and `bail` macros, which are the main
entry points to anyhow. It does not prevent using the error/result types
as they're often just passed through.

Part of MaterializeInc/database-issues#9092

Signed-off-by: Moritz Hoffmann <[email protected]>
Signed-off-by: Moritz Hoffmann <[email protected]>
@antiguru antiguru requested review from a team, ggevay, teskje and ParkMyCar as code owners April 9, 2025 08:41
Copy link
Contributor

@pH14 pH14 left a comment

Choose a reason for hiding this comment

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

The risks outlined in https://github.com/MaterializeInc/database-issues/issues/9092 seem reasonable, but we should also make the path forward very obvious to anyone touching the code because it might be surprising that anyhow is to be avoided.

Following the deprecation warnings, we should be able to answer:

  • If someone is writing net-new error handling code, what does it look like in absence of anyhow? Are there any references to model after?
  • If someone needs to update the existing code, what should they do?

@@ -88,9 +88,12 @@ disallowed-macros = [
{ path = "proptest::prop_oneof", reason = "use `proptest::strategy::Union::new` instead" },
{ path = "log::log", reason = "use the macros provided by `tracing` instead (database-issues#3001)" },
{ path = "tracing::instrument", reason = "use `mz_ore::instrument` instead" },
{ path = "anyhow::anyhow", reason = "use structured errors instead" },
{ path = "anyhow::bail", reason = "use structured errors instead" },
Copy link
Contributor

Choose a reason for hiding this comment

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

imo this would be more valuable with a fleshed out example to point people towards

@@ -7,6 +7,9 @@
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0.

// database-issues#9092: anyhow should not be used.
Copy link
Contributor

Choose a reason for hiding this comment

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

the breadcrumb trail here should also lead folks to the right solution

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.

2 participants