Skip to content

Commit

Permalink
Merge pull request #5 from MindscapeHQ/fix-when-exception-messages-ar…
Browse files Browse the repository at this point in the history
…e-too-long-to-use-as-file-name

Fix when exception messages are too long to use as file name
  • Loading branch information
QuantumNightmare authored Jul 17, 2024
2 parents 57db3ae + eb4a089 commit 28f964f
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGE-LOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Change Log for Raygun.Aspire.Hosting.Raygun

### v2.0.2
- Fixed a bug where exceptions with long message names could not be saved.

### v2.0.1
- Fixed a bug where new exception reports would be displayed as occurring 12 hours ago if they occurred after midday UTC (because of formatting dates with 12 hour time instead of 24 hour time - losing the precision for subsequent time logic).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<RepositoryType>git</RepositoryType>
<PackageProjectUrl>https://raygun.com/platform/crash-reporting</PackageProjectUrl>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<Version>2.0.1</Version>
<Version>2.0.2</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public static IResourceBuilder<RaygunAspireWebAppResource> AddRaygun(this IDistr
{
var raygun = new RaygunAspireWebAppResource(name);
return builder.AddResource(raygun)
.WithAnnotation(new ContainerImageAnnotation { Image = "raygunowner/raygun-aspire-portal", Tag = "2.0.1" })
.WithAnnotation(new ContainerImageAnnotation { Image = "raygunowner/raygun-aspire-portal", Tag = "2.0.2" })
.WithAnnotation(new EndpointAnnotation(ProtocolType.Tcp, uriScheme: "http", port: port, targetPort: 8080))
.WithVolume("raygun-data", "/app/raygun")
.ExcludeFromManifest()
Expand Down
4 changes: 2 additions & 2 deletions src/RaygunAspireWebApp/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private ErrorInstanceRow ConvertFileInfoToErrorInstance(FileInfo fileInfo)
fileName = fileName.Substring(index + 1);
}

string decodedFilename = HttpUtility.UrlDecode(fileName);
var decodedFilename = HttpUtility.UrlDecode(fileName);

if (decodedFilename.EndsWith(".json"))
{
Expand All @@ -71,7 +71,7 @@ private ErrorInstanceRow ConvertFileInfoToErrorInstance(FileInfo fileInfo)

return new ErrorInstanceRow
{
Timestamp = fileInfo.LastWriteTime,
Timestamp = fileInfo.LastWriteTimeUtc,
Name = decodedFilename,
Id = id
};
Expand Down
21 changes: 17 additions & 4 deletions src/RaygunAspireWebApp/Controllers/IngestionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public async Task<IActionResult> Entries()
try
{
using var reader = new StreamReader(Request.Body, Encoding.UTF8);
string requestBody = await reader.ReadToEndAsync();
var requestBody = await reader.ReadToEndAsync();

var raygunMessage = JsonSerializer.Deserialize<Mindscape.Raygun4Net.RaygunMessage>(requestBody, new JsonSerializerOptions { PropertyNameCaseInsensitive = true, Converters = { new RaygunIdentifierMessageConverter() } });

Expand All @@ -41,9 +41,17 @@ public async Task<IActionResult> Entries()
message = "Unknown error";
}

string noAsterisk = message.Replace("*", "");
string encodedMessage = HttpUtility.UrlEncode(noAsterisk);
System.IO.File.WriteAllText($"{ErrorsFolderPath}/{uniqueSlug}-{encodedMessage}.json", requestBody);
var noAsterisk = message.Replace("*", "");
var encodedMessage = HttpUtility.UrlEncode(noAsterisk);

var fileName = BuildFileName(uniqueSlug, encodedMessage);
if (fileName.Length > 255)
{
encodedMessage = encodedMessage.Substring(0, encodedMessage.Length - (fileName.Length - 255) - 3) + "...";
fileName = BuildFileName(uniqueSlug, encodedMessage);
}

System.IO.File.WriteAllText($"{ErrorsFolderPath}/{fileName}", requestBody);

EnforceRetentionAsync();
}
Expand All @@ -57,6 +65,11 @@ public async Task<IActionResult> Entries()
return Accepted();
}

private string BuildFileName(long uniqueSlug, string encodedMessage)
{
return $"{uniqueSlug}-{encodedMessage}.json";
}

private static void EnforceRetentionAsync()
{
var files = Directory.GetFiles(ErrorsFolderPath)
Expand Down
2 changes: 1 addition & 1 deletion src/RaygunAspireWebApp/RaygunAspireWebApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<version>2.0.1</version>
<version>2.0.2</version>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 28f964f

Please sign in to comment.