From dc9695f1239d0e4024cdd7dfdba4ed778889c5b4 Mon Sep 17 00:00:00 2001 From: eric sciple Date: Thu, 20 Mar 2025 20:09:00 -0500 Subject: [PATCH] Increase error body max length before truncation (#3762) --- src/Sdk/RSWebApi/RunServiceHttpClient.cs | 7 ++++--- .../L0/Sdk/RSWebApi/RunServiceHttpClientL0.cs | 20 +++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 src/Test/L0/Sdk/RSWebApi/RunServiceHttpClientL0.cs diff --git a/src/Sdk/RSWebApi/RunServiceHttpClient.cs b/src/Sdk/RSWebApi/RunServiceHttpClient.cs index 66bd08a98..bb1407706 100644 --- a/src/Sdk/RSWebApi/RunServiceHttpClient.cs +++ b/src/Sdk/RSWebApi/RunServiceHttpClient.cs @@ -253,11 +253,12 @@ namespace GitHub.Actions.RunService.WebApi return false; } - private static string Truncate(string errorBody) + internal static string Truncate(string errorBody) { - if (errorBody.Length > 100) + const int maxLength = 200; + if (errorBody.Length > maxLength) { - return errorBody.Substring(0, 100) + "[truncated]"; + return errorBody.Substring(0, maxLength) + "[truncated]"; } return errorBody; diff --git a/src/Test/L0/Sdk/RSWebApi/RunServiceHttpClientL0.cs b/src/Test/L0/Sdk/RSWebApi/RunServiceHttpClientL0.cs new file mode 100644 index 000000000..b4f3e54ac --- /dev/null +++ b/src/Test/L0/Sdk/RSWebApi/RunServiceHttpClientL0.cs @@ -0,0 +1,20 @@ +using GitHub.Actions.RunService.WebApi; +using Xunit; + +namespace GitHub.Actions.RunService.WebApi.Tests; + +public sealed class RunServiceHttpClientL0 +{ + [Fact] + public void Truncate() + { + TestTruncate(string.Empty.PadLeft(199, 'a'), string.Empty.PadLeft(199, 'a')); + TestTruncate(string.Empty.PadLeft(200, 'a'), string.Empty.PadLeft(200, 'a')); + TestTruncate(string.Empty.PadLeft(201, 'a'), string.Empty.PadLeft(200, 'a') + "[truncated]"); + } + + private void TestTruncate(string errorBody, string expected) + { + Assert.Equal(expected, RunServiceHttpClient.Truncate(errorBody)); + } +}