Files
alknet/tasks/cleanup/panic-free-static-config.md
glm-5.1 b0a885ea40 fix(config): replace panics in parse_proxy_config with proper Result errors
parse_proxy_config was using expect()/unwrap()/panic!() which would
crash the process on malformed proxy config strings instead of
returning a descriptive error. Now returns ConfigError::ProxyConfigInvalid
with the specific issue (bad scheme, bad address). Added tests for
invalid scheme, invalid address, and end-to-end from_serve_options.
2026-06-08 05:30:23 +00:00

43 lines
2.0 KiB
Markdown

---
id: cleanup/panic-free-static-config
name: Replace panic/expect/unwrap with Result-based error handling in StaticConfig
status: completed
depends_on:
- review/phase1-core-modifications
scope: narrow
risk: low
impact: component
level: implementation
---
## Description
The `parse_proxy_config` function and related code in `crates/alknet-core/src/config/static_config.rs` uses `expect()`, `panic!()`, and bare `unwrap()` calls. This is bad form for production code — panics in library code should be avoided unless truly unreachable.
Since `StaticConfig::from_serve_options()` already returns `Result<..., ConfigError>`, the proxy config parsing should propagate errors through the `Result` chain instead of panicking. A misconfigured proxy string should produce a clear `ConfigError`, not crash the process.
**Fix**:
- Replace `expect()` and `panic!()` in `parse_proxy_config` with proper `Result::Err` returns
- Replace bare `unwrap()` calls with `?` or explicit error mapping
- Ensure all error paths produce meaningful `ConfigError` variants
## Acceptance Criteria
- [ ] No `panic!()`, `expect()`, or bare `unwrap()` in `static_config.rs` production code paths
- [ ] All error paths return `Result<..., ConfigError>` with descriptive messages
- [ ] Invalid proxy config strings produce clear errors instead of panicking
- [ ] All existing tests pass
- [ ] New test: malformed proxy string returns `Err(ConfigError)`, doesn't panic
## References
- crates/alknet-core/src/config/static_config.rs — lines with panic/expect/unwrap
- crates/alknet-core/src/error.rs — ConfigError type
## Notes
> Identified during Phase 1 review (W5)
## Summary
> Replaced all panic!/expect()/unwrap() in parse_proxy_config with Result-based error handling. Added ConfigError::ProxyConfigInvalid variant. Invalid proxy scheme or malformed address now returns clear errors instead of panicking. Added 4 new tests covering invalid scheme, invalid address, and from_serve_options error propagation.