refactor: replace regex JSON parsing with DataContractJsonSerializer#40
Conversation
|
Warning Review limit reached
Next review available in: 31 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| catch | ||
| { | ||
| if (match.Success) values.Add(Regex.Unescape(match.Groups["value"].Value)); | ||
| return new string[0]; | ||
| } |
There was a problem hiding this comment.
The catch block in ExtractVersionTags (lines 222-225) silently swallows all exceptions and returns an empty array. This can obscure the root cause of failures, making debugging difficult if the JSON format changes or network responses are malformed.
Recommendation: At minimum, log the exception or provide a mechanism to surface the error, such as rethrowing or returning an error indicator. For example:
catch (Exception ex)
{
// Log the exception or rethrow
// Logger.LogError(ex, "Failed to extract version tags from JSON");
return new string[0];
}- Add GitHubRelease DTO and deserialize the GitHub API response properly. - Use System.Runtime.Serialization.Json.DataContractJsonSerializer (built into .NET Framework 4.8). - Preserve existing fallback behavior: invalid/empty responses yield no tags. - Remove Regex using directive. - dotnet test passes 58/58. Closes #36.
f641293 to
b34b742
Compare
|
|
||
| cancellationToken.ThrowIfCancellationRequested(); | ||
| string json = await client.DownloadStringAsync(ReleasesApiUrl, cancellationToken); | ||
| string tagName = GetNewestVersionTag(ExtractJsonStrings(json, "tag_name").ToArray()); | ||
| string tagName = GetNewestVersionTag(ExtractVersionTags(json)); | ||
|
|
||
| UpdateInfo info = new UpdateInfo(); | ||
| info.LatestVersion = tagName; |
There was a problem hiding this comment.
Potential Issue: Lack of Validation for tagName in UpdateInfo Construction
The code assigns tagName directly to UpdateInfo.LatestVersion and uses it to build URLs without validating that it is non-null and well-formed. If ExtractVersionTags or GetNewestVersionTag returns an empty or malformed string, this could result in broken URLs or incorrect update status.
Recommendation: Add validation for tagName before constructing URLs and setting IsUpdateAvailable. For example:
if (string.IsNullOrEmpty(tagName)) {
// Handle the error, e.g., return null or a default UpdateInfo indicating no update
}This will prevent propagating invalid data and improve robustness.
Summary\r\nReplace the fragile regex-based extraction of release tags with proper JSON deserialization.\r\n\r\n## Changes\r\n- Add DTO with .\r\n- Use to parse the GitHub releases API response.\r\n- This serializer is built into .NET Framework 4.8, so no new external dependencies are required.\r\n- Preserve existing fallback: invalid or empty responses yield no tags.\r\n\r\n## Tests\r\n- MSBUILD : error MSB1003: Specify a project or solution file. The current working directory does not contain a project or solution file. passes: 58/58.\r\n\r\nCloses #36.