You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Refactor: Improve error handling, update dependencies, and refactor config (#14)
* Refactor: Improve error handling, update dependencies, and refactor config
This commit introduces several improvements to the adr tool:
1. **Error Handling**: I replaced all `panic()` calls with proper error returns, particularly in the `helpers.go` module. Errors are now propagated up and handled gracefully by the command actions in `commands.go`, providing clearer, user-friendly messages.
2. **Update Deprecated `ioutil`**: I replaced all instances of the deprecated `io/ioutil` package with equivalent functions from the `os` and `io` packages (e.g., `os.ReadFile`, `os.WriteFile`).
3. **Configuration Management**:
* I refactored global path variables in `helpers.go` into a `PathConfig` struct, which is initialized at startup. This centralizes path management and reduces global state.
* I added a `GetDefaultBaseFolder()` getter in `helpers.go` and updated `commands.go` to use it, ensuring consumers of these paths use the new centralized configuration.
4. **Testing**:
* I updated existing tests in `helpers_test.go` and `main_test.go` to align with the new error handling mechanisms (expecting returned errors instead of panics) and the `PathConfig` refactoring.
* I added new tests to cover `NewPathConfig`, `GetDefaultBaseFolder`, and the scenario of running the `new` command before `init`.
* I improved test setup and teardown for better isolation and cleanup, including the use of temporary directories for test-specific configurations.
These changes enhance the robustness, maintainability, and testability of the application.
* Refactor: Improve error handling, update dependencies, and refactor config
This commit introduces several improvements to the adr tool:
1. **Error Handling**: I replaced all `panic()` calls with proper error returns, particularly in the `helpers.go` module. Errors are now propagated up and handled gracefully by the command actions in `commands.go`, providing clearer, user-friendly messages.
2. **Update Deprecated `ioutil`**: I replaced all instances of the deprecated `io/ioutil` package with equivalent functions from the `os` and `io` packages (e.g., `os.ReadFile`, `os.WriteFile`).
3. **Configuration Management**:
* I refactored global path variables in `helpers.go` into a `PathConfig` struct, which is initialized at startup. This centralizes path management and reduces global state.
* I added a `GetDefaultBaseFolder()` getter in `helpers.go` and updated `commands.go` to use it, ensuring consumers of these paths use the new centralized configuration.
4. **Testing**:
* I updated existing tests in `helpers_test.go` and `main_test.go` to align with the new error handling mechanisms (expecting returned errors instead of panics) and the `PathConfig` refactoring.
* I added new tests to cover `NewPathConfig`, `GetDefaultBaseFolder`, and the scenario of running the `new` command before `init`.
* I improved test setup and teardown for better isolation and cleanup, including the use of temporary directories for test-specific configurations.
* I corrected a typo in `main_test.go` (`tErrorf` to `t.Errorf`).
These changes enhance the robustness, maintainability, and testability of the application.
---------
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
0 commit comments