Refactor docgen: improve error handling and file operations#6103
Refactor docgen: improve error handling and file operations#6103ehsandeep merged 2 commits intoprojectdiscovery:devfrom Mehran-Seifalinia:dev
Conversation
Moved the argument check to the start of main() so we don’t do any unnecessary work if the arguments aren’t provided. Also added proper error handling for encoder.Encode(jsonschemaData), since it was failing silently before. Switched os.WriteFile to os.Create for better file handling and error reporting. To clean things up, I added a writeToFile() function to remove duplicate code. For replacing schema paths, I used ReplaceAllString() instead of looping through matches—it’s cleaner and a bit more efficient. Also renamed r to t in the Namer function to make things clearer.
WalkthroughThe changes introduce a new function Changes
Sequence Diagram(s)sequenceDiagram
participant M as Main Function
participant W as writeToFile Function
participant FS as File System
M->>W: Invoke writeToFile(filename, data)
W->>FS: Create/Open file with filename
FS-->>W: Return file handle or error
W->>FS: Write data to file
FS-->>W: Confirm write or return error
W-->>M: Return success/error status
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🔇 Additional comments (6)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
Thanks for your contribution @Mehran-Seifalinia ! :) |
|
Do I need to change the code and submit it again to fix the Lint error, or will the development team handle resolving it? |
@Mehran-Seifalinia feel free to push additonal commit to resolve lint error: |
- Remove importing string
Moved the argument check to the start of main() so we don’t do any unnecessary work if the arguments aren’t provided. Also added proper error handling for encoder.Encode(jsonschemaData), since it was failing silently before.
Switched os.WriteFile to os.Create for better file handling and error reporting. To clean things up, I added a writeToFile() function to remove duplicate code.
For replacing schema paths, I used ReplaceAllString() instead of looping through matches—it’s cleaner and a bit more efficient. Also renamed r to t in the Namer function to make things clearer.
Proposed changes
Checklist
Summary by CodeRabbit