Skip to content

Commit

Permalink
CA-383054: Corrected error parsing so it shows missing prerequisite d…
Browse files Browse the repository at this point in the history
…etails.

Signed-off-by: Konstantina Chremmou <[email protected]>
  • Loading branch information
kc284 committed Oct 23, 2023
1 parent 6729a94 commit b199591
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions XenAdmin/Diagnostics/Checks/PatchPrecheckCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,8 @@ private Problem FindProblem(string result)
log.Error(m.ToString());
XmlNode errorNode = doc.FirstChild;

string errorcode = errorNode.Attributes != null && errorNode.Attributes["errorcode"] != null
? errorNode.Attributes["errorcode"].Value
: string.Empty;

if (errorcode == "")
string errorCode = errorNode.Attributes?["errorcode"]?.Value;
if (string.IsNullOrEmpty(errorCode))
return null;

var found = "";
Expand All @@ -154,8 +151,18 @@ private Problem FindProblem(string result)
else if (node.Name == "required")
required = node.InnerXml;
}
var problem = FindProblem(errorcode, "", found, required);
return problem ?? new PrecheckFailed(this, Host, new Failure(errorcode));

switch (errorCode)
{
case "UPDATE_PRECHECK_FAILED_CONFLICT_PRESENT" when !string.IsNullOrEmpty(found):
return new ConflictingUpdatePresent(this, found, Host);

case "UPDATE_PRECHECK_FAILED_PREREQUISITE_MISSING" when !string.IsNullOrEmpty(required):
return new PrerequisiteUpdateMissing(this, required, Host);
}

var problem = FindProblem(errorCode, "", found, required);
return problem ?? new PrecheckFailed(this, Host, new Failure(errorCode));
}

/// <summary>
Expand Down Expand Up @@ -188,17 +195,17 @@ private Problem FindProblem(Failure failure)
if (failure.ErrorDescription.Count == 0)
return null;

var errorcode = failure.ErrorDescription[0];
var errorCode = failure.ErrorDescription[0];
var param1 = failure.ErrorDescription.Count > 1 ? failure.ErrorDescription[1] : "";
var param2 = failure.ErrorDescription.Count > 2 ? failure.ErrorDescription[2] : "";
var param3 = failure.ErrorDescription.Count > 3 ? failure.ErrorDescription[3] : "";

return FindProblem(errorcode, param1, param2, param3);
return FindProblem(errorCode, param1, param2, param3);
}

private Problem FindProblem(string errorcode, string param1, string param2, string param3)
private Problem FindProblem(string errorCode, string param1, string param2, string param3)
{
switch (errorcode)
switch (errorCode)
{
case "UPDATE_PRECHECK_FAILED_WRONG_SERVER_VERSION":
return new WrongServerVersion(this, Host);
Expand All @@ -207,7 +214,7 @@ private Problem FindProblem(string errorcode, string param1, string param2, stri
return new ConflictingUpdatePresent(this, param2, Host);

case "UPDATE_PRECHECK_FAILED_PREREQUISITE_MISSING":
return new PrerequisiteUpdateMissing(this, param3, Host);
return new PrerequisiteUpdateMissing(this, param2, Host);

case "UPDATE_PRECHECK_FAILED_OUT_OF_SPACE":
long.TryParse(param2, out var foundSpace);
Expand Down Expand Up @@ -245,8 +252,8 @@ private Problem FindProblem(string errorcode, string param1, string param2, stri
return new VSwitchControllerProblem(this, pool);
return null;
}
else
return FindProblem(param2);

return FindProblem(param2);
}
return null;
}
Expand Down

0 comments on commit b199591

Please sign in to comment.