Skip to content

[Codebase Audit] Reduce panic-prone calls in src/metrics/mod.rs #553

Description

@kelly-musk

Problem

src/metrics/mod.rs contains 85 panic-prone calls (unwrap, expect, or panic!).

Evidence

  • src/metrics/mod.rs:41.expect("encoding metrics failed");
  • src/metrics/mod.rs:42String::from_utf8(buf).expect("metrics output is not valid UTF-8")
  • src/metrics/mod.rs:57HTTP_REQUESTS_TOTAL.get().expect("metrics not initialised")
  • src/metrics/mod.rs:63.expect("metrics not initialised")
  • src/metrics/mod.rs:69.expect("metrics not initialised")

Proposed fix

Replace non-essential unwrap/expect usages with typed error propagation and contextual logging. Keep explicit panics only where unrecoverable invariants are well-documented.

Acceptance criteria

  • All avoidable panic-prone calls in this file are removed or justified with comments/tests.
  • Error paths return typed errors and preserve observability context.
  • Existing tests pass (or new tests cover changed paths).

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave program

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions