refactor(errors): extract network hint dispatch and formatting#824
Conversation
sonukapoor
left a comment
There was a problem hiding this comment.
Thanks for picking this up - the 20-line if/else block is genuine duplication and extracting it is the right call. The routing logic is clean and the behavioral output is preserved exactly.
My main concern is the module placement. formatHintLines is a chalk formatting utility - it does the same work as formatRelationshipLabel and formatAdvisorySourceLine in formatters.ts, so that's where it belongs. And getNetworkErrorHint has no chalk dependency at all - it only calls functions that already live in network.ts, so it fits there naturally. Those two moves achieve the full index.ts cleanup you're after without needing a new cli-errors.ts file.
The other gap is tests. Every detection function in network.ts is covered in tests/network.test.ts - the two new functions should get the same treatment. formatHintLines has an empty-input branch, getNetworkErrorHint has five branches, both need coverage.
|
Thanks, that makes sense. I’ll drop the new cli-errors module and move the helpers into the existing boundaries: formatHintLines into output/formatters.ts, and getNetworkErrorHint into utils/network.ts. I’ll also add coverage for the empty formatHintLines input case and all five getNetworkErrorHint branches. |
sonukapoor
left a comment
There was a problem hiding this comment.
This is exactly what I was looking for - formatHintLines in formatters.ts alongside the other chalk formatting helpers, getNetworkErrorHint in network.ts where all the detection logic already lives, and no new file needed. The test coverage is thorough too: all five branches of getNetworkErrorHint in network.test.ts and both paths of formatHintLines in output.test.ts. Well done.
What
Extract network error hint dispatch and hint-line formatting out of
src/index.ts.getNetworkErrorHint()now lives insrc/utils/network.ts, andformatHintLines()now lives insrc/output/formatters.ts.Why
utils/network.tsoutput/formatters.tsChanges
src/utils/network.ts: addgetNetworkErrorHint()for network hint dispatchsrc/output/formatters.ts: addformatHintLines()for shared hint formattingsrc/index.ts: replace repeated network hint if/else block with composed helper callsgetNetworkErrorHint()branches andformatHintLines()formatting behaviorTesting
fetchErrorCaCertHint)Closes #823