Skip to content

Commit

Permalink
Merge pull request Dynatrace#44 from Dynatrace/improve-errormsg
Browse files Browse the repository at this point in the history
show better errors in case deserialization of json fails
  • Loading branch information
discostu105 authored Mar 28, 2017
2 parents 6e535f7 + 2fc4218 commit 07f24d8
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 15 deletions.
4 changes: 2 additions & 2 deletions building/msbuild.targets
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<MSBuild Projects="$(RootFolder)\src\SuperDumpSelector\SuperDumpSelector.csproj" Properties="Configuration=$(Configuration);Platform=AnyCPU;OutputPath=$(RootFolder)\build\bin\SuperDumpSelector" Targets="Build" />

<MSBuild Projects="$(RootFolder)\src\SuperDumpService\SuperDumpService.csproj" Properties="Configuration=$(Configuration);Platform=AnyCPU" Targets="Build" />
<MSBuild Projects="$(RootFolder)\src\SuperDumpService\SuperDumpService.csproj" Properties="DeployOnBuild=true;PublishProfile=publish-profile" />
<MSBuild Projects="$(RootFolder)\src\SuperDumpService\SuperDumpService.csproj" Properties="DeployOnBuild=true;PublishProfile=FolderProfile" />

<MSBuild Projects="$(RootFolder)\src\SuperDump.DebugDiag\SuperDump.DebugDiag.csproj" Properties="Configuration=$(Configuration);Platform=AnyCPU;OutputPath=$(RootFolder)\build\bin\SuperDump.DebugDiag" Targets="Build" />
</Target>
Expand All @@ -32,7 +32,7 @@
<MSBuild Projects="$(RootFolder)\src\SuperDumpSelector\SuperDumpSelector.csproj" Properties="Configuration=$(Configuration);Platform=AnyCPU;OutputPath=$(RootFolder)\build\bin\SuperDumpSelector" Targets="Build" />

<MSBuild Projects="$(RootFolder)\src\SuperDumpService\SuperDumpService.csproj" Properties="Configuration=$(Configuration);Platform=x86" Targets="Build" />
<MSBuild Projects="$(RootFolder)\src\SuperDumpService\SuperDumpService.csproj" Properties="DeployOnBuild=true;PublishProfile=publish-profile" />
<MSBuild Projects="$(RootFolder)\src\SuperDumpService\SuperDumpService.csproj" Properties="DeployOnBuild=true;PublishProfile=FolderProfile" />

<MSBuild Projects="$(RootFolder)\src\SuperDump.DebugDiag\SuperDump.DebugDiag.csproj" Properties="Configuration=$(Configuration);Platform=AnyCPU;OutputPath=$(RootFolder)\build\bin\SuperDump.DebugDiag" Targets="Build" />
</Target>
Expand Down
5 changes: 3 additions & 2 deletions src/SuperDumpService/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public IActionResult Report(string bundleId, string dumpId) {
return View(null);
}

SDResult res = superDumpRepo.GetResult(bundleId, dumpId);
SDResult res = superDumpRepo.GetResult(bundleId, dumpId, out string error);

return base.View(new ReportViewModel(bundleId, dumpId) {
BundleFileName = bundleInfo.BundleFileName,
Expand All @@ -140,7 +140,8 @@ public IActionResult Report(string bundleId, string dumpId) {
AnalysisError = dumpInfo.ErrorMessage,
ThreadTags = res != null ? res.GetThreadTags() : new HashSet<SDTag>(),
PointerSize = res == null ? 8 : (res.SystemContext.ProcessArchitecture == "X86" ? 8 : 12),
CustomTextResult = ReadCustomTextResult(dumpInfo)
CustomTextResult = ReadCustomTextResult(dumpInfo),
SDResultReadError = error
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/SuperDumpService/Controllers/api/DumpsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public IActionResult Get(string bundleId) {

var resultList = new List<SDResult>();
foreach (var dumpInfo in dumpRepo.Get(bundleId)) {
resultList.Add(superDumpRepo.GetResult(bundleId, dumpInfo.DumpId));
resultList.Add(superDumpRepo.GetResult(bundleId, dumpInfo.DumpId, out string error));
}
return Content(JsonConvert.SerializeObject(resultList, Formatting.Indented, new JsonSerializerSettings {
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ by editing this MSBuild file. In order to learn more about this please visit htt
<SiteUrlToLaunchAfterPublish />
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<PublishFramework>netcoreapp1.1</PublishFramework>
<PublishFramework />
<ProjectGuid>f362a805-cad7-44a5-a6e3-6f69dd429c8e</ProjectGuid>
<publishUrl>..\..\build\bin\SuperDumpService</publishUrl>
<DeleteExistingFiles>False</DeleteExistingFiles>
Expand Down
2 changes: 1 addition & 1 deletion src/SuperDumpService/Services/BundleStorageFilebased.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private void CreateBundleMetainfoForCompat(string bundleId) {
metainfo.Created = dump.Created;
metainfo.Finished = dump.Created; // can't do better.
metainfo.Status = BundleStatus.Finished;
var fullresult = dumpStorage.ReadResults(bundleId, dump.DumpId);
var fullresult = dumpStorage.ReadResults(bundleId, dump.DumpId, out string error);
if (fullresult != null) {
if (!string.IsNullOrEmpty(fullresult.AnalysisInfo.JiraIssue)) metainfo.CustomProperties["ref"] = fullresult.AnalysisInfo.JiraIssue;
if (!string.IsNullOrEmpty(fullresult.AnalysisInfo.FriendlyName)) metainfo.CustomProperties["note"] = fullresult.AnalysisInfo.FriendlyName;
Expand Down
6 changes: 3 additions & 3 deletions src/SuperDumpService/Services/DumpRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void PopulateForBundle(string bundleId) {
if (!dumpInfo.Is64Bit.HasValue) {
// this is done for repos, which did not store bitness information yet
// be aware that this will slow down startup considerable.
var res = storage.ReadResults(bundleId, dumpInfo.DumpId);
var res = storage.ReadResults(bundleId, dumpInfo.DumpId, out string error);
if (res != null) {
dumpInfo.Is64Bit = res.SystemContext.ProcessArchitecture.Contains("64");
storage.Store(dumpInfo);
Expand Down Expand Up @@ -118,8 +118,8 @@ public string CreateUniqueDumpId() {
}
}

internal SDResult GetResult(string bundleId, string dumpId) {
return storage.ReadResults(bundleId, dumpId);
internal SDResult GetResult(string bundleId, string dumpId, out string error) {
return storage.ReadResults(bundleId, dumpId, out error);
}

internal IEnumerable<SDFileInfo> GetFileNames(string bundleId, string dumpId) {
Expand Down
8 changes: 5 additions & 3 deletions src/SuperDumpService/Services/DumpStorageFilebased.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private void CreateMetainfoForCompat(string bundleId, string dumpId) {
BundleId = bundleId,
DumpId = dumpId
};
var result = ReadResults(bundleId, dumpId);
var result = ReadResults(bundleId, dumpId, out string error);
if (result != null) {
metainfo.Status = DumpStatus.Finished;
metainfo.DumpFileName = result.AnalysisInfo.Path?.Replace(pathHelper.GetUploadsDir(), ""); // AnalysisInfo.FileName used to store full file names. e.g. "C:\superdump\uploads\myzipfilename\subdir\dump.dmp". lets only keep "myzipfilename\subdir\dump.dmp"
Expand All @@ -64,7 +64,8 @@ private void CreateMetainfoForCompat(string bundleId, string dumpId) {
WriteMetainfoFile(metainfo, pathHelper.GetDumpMetadataPath(bundleId, dumpId));
}

public SDResult ReadResults(string bundleId, string dumpId) {
public SDResult ReadResults(string bundleId, string dumpId, out string error) {
error = string.Empty;
var filename = pathHelper.GetJsonPath(bundleId, dumpId);
if (!File.Exists(filename)) {
// fallback for older dumps
Expand All @@ -74,7 +75,8 @@ public SDResult ReadResults(string bundleId, string dumpId) {
try {
return JsonConvert.DeserializeObject<SDResult>(File.ReadAllText(filename));
} catch (Exception e) {
Console.WriteLine($"could not deserialize {filename}: {e.Message}");
error = $"could not deserialize {filename}: {e.Message}";
Console.WriteLine(error);
return null;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/SuperDumpService/Services/SuperDumpRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public SuperDumpRepository(
pathHelper.PrepareDirectories();
}

public SDResult GetResult(string bundleId, string dumpId) {
return dumpRepo.GetResult(bundleId, dumpId);
public SDResult GetResult(string bundleId, string dumpId, out string error) {
return dumpRepo.GetResult(bundleId, dumpId, out error);
}

public bool ContainsBundle(string bundleId) {
Expand Down
3 changes: 3 additions & 0 deletions src/SuperDumpService/SuperDumpService.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,7 @@
<ProjectReference Include="..\SuperDump.Common\SuperDump.Common.csproj" />
<ProjectReference Include="..\SuperDumpModels\SuperDumpModels.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\PublishProfiles\" />
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions src/SuperDumpService/ViewModels/ReportViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class ReportViewModel {
public int PointerSize { get; set; }
public IDictionary<string, string> CustomProperties { get; set; } = new Dictionary<string, string>();
public string CustomTextResult { get; set; }
public string SDResultReadError { get; set; }

public ReportViewModel(string bundleId, string dumpId) {
this.BundleId = bundleId;
Expand Down
7 changes: 7 additions & 0 deletions src/SuperDumpService/Views/Home/Report.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@
<pre>Error: @Model.AnalysisError</pre>
} else if (Model.Result == null) {
if (Model.CustomTextResult != null) {
@if (string.IsNullOrEmpty(Model.SDResultReadError)) {
<p>SuperDump Model is null for unknown reason. Falling back to CustomTextResult.</p>
} else {
<p>SuperDump Model is null, because of error:</p>
<pre>@Model.SDResultReadError</pre>
<p>Falling back to CustomTextResult.</p>
}
<section>
<pre>@Model.CustomTextResult</pre>
</section>
Expand Down

0 comments on commit 07f24d8

Please sign in to comment.