Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not throw exceptions for empty model number #1243

Merged
merged 4 commits into from
Nov 19, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions backend/LexBoxApi/Services/HgService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,19 @@
{
var result = await ExecuteHgCommandServerCommand(code, "flexmodelversion", token);
var text = await result.ReadAsStringAsync(token);
var json = JsonDocument.Parse(text);
return json.RootElement.GetProperty("modelversion").GetInt32();
if (string.IsNullOrEmpty(text)) return null;
hahn-kev marked this conversation as resolved.
Show resolved Hide resolved
try
{
var json = JsonDocument.Parse(text);
if (json.RootElement.GetProperty("modelversion").TryGetInt32(out int version)) return version;
hahn-kev marked this conversation as resolved.
Show resolved Hide resolved
_logger.LogError("Invalid model version in GetModelVersionOfFlexProject, should be a number but got {modelversion}", json.RootElement.GetProperty("modelversion").ToString());
return null;
}
catch (JsonException e)
{
_logger.LogError("Malformed JSON {text} in GetModelVersionOfFlexProject: {error}", text, e.ToString());
return null;
}
}

public Task RevertRepo(ProjectCode code, string revHash)
Expand Down Expand Up @@ -445,7 +456,7 @@
{
var hash = await GetTipHash(code, timeoutSource.Token);
var isEmpty = hash == AllZeroHash;
done = expectedState switch

Check warning on line 459 in backend/LexBoxApi/Services/HgService.cs

View workflow job for this annotation

GitHub Actions / Build API / publish-api

The switch expression does not handle some values of its input type (it is not exhaustive) involving an unnamed enum value. For example, the pattern '(LexBoxApi.Services.RepoEmptyState)2' is not covered.
{
RepoEmptyState.Empty => isEmpty,
RepoEmptyState.NonEmpty => !isEmpty
Expand Down
Loading