Skip to content

refactor: Clean up workspace dependencies, eliminate unwrap panics, and improve code safety#179

Merged
Ghoul4500 merged 22 commits into
OpenGamingCollective:mainfrom
scardracs:code-cleanup-and-safety
Jul 26, 2026
Merged

refactor: Clean up workspace dependencies, eliminate unwrap panics, and improve code safety#179
Ghoul4500 merged 22 commits into
OpenGamingCollective:mainfrom
scardracs:code-cleanup-and-safety

Conversation

@scardracs

@scardracs scardracs commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

📌 Summary

This Pull Request combines workspace dependency cleanup with a comprehensive codebase refactoring aimed at code safety, panic elimination, leftover debug macro cleanup, and structural improvements across all asusctl crates and daemons.

Main Objectives:

  1. Centralize & Clean Up Dependencies: Centralize external dependencies into workspace.dependencies, replace the unmaintained external sg git crate with a native rog-scsi SCSI implementation, and pin crate versions cleanly.
  2. Panic & .unwrap() Elimination: Systematically replace .unwrap() and panic! calls with explicit error propagation (?), safe matching, and fallbacks in asusd, asusctl, rog-control-center, rog-aura, rog-platform, rog-profiles, and config-traits.
  3. Debug Code Cleanup: Remove leftover dbg! macros from production code paths.
  4. Unsafe Reduction & Atomic I/O: Replace unsafe blocks with safe Rust abstractions where possible, and enforce atomic file writing in config-traits.

🚀 Key Changes Breakdown

📦 1. Workspace Dependencies & Build Infrastructure

  • Native SCSI Implementation: Replaced the external git dependency sg with a dedicated, memory-safe native implementation (rog-scsi/src/sg.rs).
  • Workspace Dependency Centralization: Consolidated shared external dependencies in the root Cargo.toml under [workspace.dependencies].
  • Cargo.toml Formatting: Alphabetically sorted workspace dependencies and pinned ron version to ^0.12.2.
  • Packaging Cleanup: Removed obsolete supergfxctl dependencies from distribution packaging files and purged unused GitLab CI configurations.

🛡️ 2. Safety & Error Handling (unwrap / panic! Removal)

  • asusd / Daemon: Replaced unwrap calls and panics in AuraConfig (StdConfig), aura_manager, ctrl_platform, and daemon initialization with error handling, default fallbacks, and logging.
  • asusctl / CLI: Handled missing or uninitialized D-Bus services gracefully without CLI panics.
  • rog-control-center / GUI:
    • Eliminated .unwrap() calls across async D-Bus proxy calls (min_value, max_value, current_value), profile change streams, and Slint UI weak handle callbacks (show_toast).
    • Replaced CLI parse failure panic! with graceful stderr output and early exit.
    • Added proper fallbacks for missing tray assets and D-Bus proxy errors.
  • rog-aura & rog-profiles: Protected sysfs parsing against out-of-bounds access and string slicing panics (Colour::from_str), added warn! logging to all else parsing branches, and used unreachable! for non-keyboard device power byte calculations per review feedback.
  • config-traits: Implemented atomic file writes via temporary files and automatic recursive parent directory creation.
  • Debug Cleanup: Removed leftover dbg! macro calls from asusctl/src/main.rs and rog-control-center/src/ui/setup_fans.rs.

⚡ 3. Safety & Unsafe Block Removal

  • Refactored unnecessary unsafe blocks in rog-aura, rog-profiles, and rog-platform to use safe standard library methods.
  • Verified all remaining 5 unsafe blocks in rog-scsi/src/sg.rs have detailed // SAFETY: invariant documentation.

🔬 Verification & Quality Assurance

All changes have been strictly verified locally against the workspace quality requirements:

  • Formatting: cargo fmt --all -- --check (Passed - 0 errors)
  • Linting (Clippy): cargo clippy --all -- -D warnings (Passed - 0 warnings)
  • Extended Lints (Cranky): cargo cranky (Passed - 0 warnings)
  • Unit & Integration Tests: cargo test --all (Passed - 58/58 test suites passing)

📜 Commit History Included in PR

  • fix(asusd): replace panics with graceful error handling and fallbacks
  • fix(rog-control-center): eliminate unwrap panics in D-Bus calls and Slint UI callbacks
  • fix: remove leftover dbg! macros from production code
  • chore: pin ron workspace dependency version to ^0.12.2
  • style: sort workspace dependencies alphabetically in Cargo.toml
  • refactor: centralize external crate dependencies into workspace.dependencies
  • refactor: replace external sg git dependency with native rog-scsi implementation
  • fix(asusctl): improve CLI robustness under missing or empty services and eliminate unwrap calls
  • fix(asusd): replace unwrap panics with error handling in daemon and inotify watchers
  • fix(rog-control-center): handle missing tray assets, D-Bus errors, and eliminate unwrap calls
  • fix(config-traits): implement atomic file writes and recursive directory creation
  • fix(rog-platform): improve CPU EPP optional handling, PCI slots check, and remove unwrap calls
  • fix(rog-profiles): eliminate panics, out-of-bounds access, and add warning logs in sysfs fan curve parsing
  • fix(rog-aura): improve LED config error handling and power state conversion safety
  • fix: prevent string slicing panics in Colour::from_str
  • refactor: remove unsafe blocks in rog-aura, rog-profiles, and rog-platform
  • chore: remove supergfxctl dependency from packaging files
  • meta: remove GitLab CI configuration and issue templates

@scardracs
scardracs marked this pull request as ready for review July 20, 2026 09:30
@scardracs
scardracs force-pushed the code-cleanup-and-safety branch 6 times, most recently from a1fc346 to 4c9c8b3 Compare July 21, 2026 15:50
@Ghoul4500 Ghoul4500 changed the title feat: Code cleanup and safety chore: code cleanup and safety Jul 23, 2026
@scardracs
scardracs force-pushed the code-cleanup-and-safety branch from 4c9c8b3 to e75c949 Compare July 24, 2026 06:18

@Ghoul4500 Ghoul4500 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Minor changes. Otherwise good job, thank you for your contribution

Comment thread rog-profiles/src/fan_curve_set.rs
Comment thread rog-aura/src/keyboard/power.rs
Comment thread rog-platform/src/cpu.rs
@scardracs
scardracs force-pushed the code-cleanup-and-safety branch from e1d16ba to ab8ea9f Compare July 25, 2026 16:22
@scardracs
scardracs force-pushed the code-cleanup-and-safety branch from ab8ea9f to 7498baa Compare July 25, 2026 16:34
@scardracs
scardracs marked this pull request as draft July 26, 2026 09:25
@scardracs scardracs changed the title chore: code cleanup and safety chore: Refactor: Clean up workspace dependencies, eliminate unwrap panics, and improve code safety Jul 26, 2026
@scardracs
scardracs marked this pull request as ready for review July 26, 2026 09:28
@scardracs
scardracs marked this pull request as draft July 26, 2026 09:39
@scardracs scardracs changed the title chore: Refactor: Clean up workspace dependencies, eliminate unwrap panics, and improve code safety refactor: Clean up workspace dependencies, eliminate unwrap panics, and improve code safety Jul 26, 2026
@scardracs
scardracs marked this pull request as ready for review July 26, 2026 12:14
@Ghoul4500
Ghoul4500 merged commit 14dd4c6 into OpenGamingCollective:main Jul 26, 2026
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