Skip to content

Commit

Permalink
Do not throw exceptions for empty model number (#1243)
Browse files Browse the repository at this point in the history
Empty projects now just return null. Projects where the model number
file is malformed (invalid JSON or whatever) now log the error, then
return null without throwing an exception.
  • Loading branch information
rmunn authored Nov 19, 2024
1 parent 3f3c556 commit 77f6b3c
Showing 1 changed file with 13 additions and 2 deletions.
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 @@ private string[] GetWsList(System.Xml.XmlElement root, string tagName)
{
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.IsNullOrWhiteSpace(text)) return null;
try
{
var json = JsonDocument.Parse(text);
if (json.RootElement.TryGetProperty("modelversion", out var modelversion) && modelversion.TryGetInt32(out int version)) return version;
_logger.LogError("Invalid JSON {text} in GetModelVersionOfFlexProject, should have one property \"modelversion\" that's a number", text);
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

0 comments on commit 77f6b3c

Please sign in to comment.