Use descriptive ErrorMessage for timed out requests#2355
Use descriptive ErrorMessage for timed out requests#2355alexeyzimarev wants to merge 2 commits intodevfrom
Conversation
… values to strings Previously, AddParameter<T>, AddQueryParameter<T>, AddUrlSegment<T>, AddHeader<T>, AddOrUpdateParameter<T>, AddOrUpdateHeader<T>, and Parameter.CreateParameter all used ToString() which respects the current culture. This caused issues on non-English locales where e.g. 1.234 would be formatted as "1,234" with a comma decimal separator. All generic overloads now default to InvariantCulture and accept an optional CultureInfo parameter for callers who need locale-specific formatting. Fixes #2270 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When a request times out, ErrorMessage was set to the TaskCanceledException
message ("A task was canceled.") which contradicts ResponseStatus.TimedOut.
Now ErrorMessage says "The request timed out." for timeout scenarios, keeping
all three state properties (ResponseStatus, ErrorMessage, ErrorException)
consistent. ErrorException still holds the original TaskCanceledException.
Fixes #2257
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Review Summary by QodoFix timeout error message and parameter culture handling
WalkthroughsDescription• Use invariant culture for parameter value conversions to fix locale-specific formatting issues • Add optional culture parameter to generic parameter methods for locale-specific formatting when needed • Use descriptive error message "The request timed out." for timeout scenarios instead of "A task was canceled." • Ensure consistency between ResponseStatus.TimedOut, ErrorMessage, and ErrorException for timeout cases Diagramflowchart LR
A["Parameter Conversion"] -->|"Use InvariantCulture by default"| B["Consistent Formatting"]
C["Timeout Exception"] -->|"Detect OperationCanceledException"| D["Set ErrorMessage to timeout message"]
D -->|"Keep ErrorException unchanged"| E["Consistent State Properties"]
B --> F["Enhanced RestSharp"]
E --> F
File Changes1. src/RestSharp/Extensions/StringExtensions.cs
|
Code Review by Qodo
1. Binary-breaking API signature change
|
|
Deploying restsharp with
|
| Latest commit: |
bf41159
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://62648670.restsharp.pages.dev |
| Branch Preview URL: | https://fix-timeout-error-message.restsharp.pages.dev |
| public RestRequest AddParameter<T>(string name, T value, bool encode = true, CultureInfo? culture = null) where T : struct | ||
| => request.AddParameter(name, value.ToStringValue(culture), encode); |
There was a problem hiding this comment.
1. Binary-breaking api signature change 🐞 Bug ⛯ Reliability
Several public generic RestRequest extension methods were changed to add a CultureInfo parameter instead of adding new overloads. This breaks binary compatibility: consumers compiled against prior versions can hit MissingMethodException at runtime when loading the updated assembly.
Agent Prompt
## Issue description
Public generic extension methods changed signatures by adding a new `CultureInfo? culture` parameter. This is source-compatible but **not binary-compatible**: existing compiled clients expecting the old signatures may fail at runtime with `MissingMethodException`.
## Issue Context
These methods are public API surface. Optional parameters do not preserve binary compatibility when the parameter is newly added (signature changes).
## Fix Focus Areas
- src/RestSharp/Request/RestRequestExtensions.cs[58-81]
- src/RestSharp/Request/RestRequestExtensions.Headers.cs[54-77]
- src/RestSharp/Request/RestRequestExtensions.Query.cs[44-45]
- src/RestSharp/Request/RestRequestExtensions.Url.cs[44-45]
## Suggested implementation sketch
- Add back overloads with the old signatures, e.g.:
- `AddParameter<T>(string name, T value, bool encode = true)` calls `AddParameter(name, value, encode, culture: null)`.
- Keep the new overload with `CultureInfo? culture = null`.
- Repeat for other affected generic methods.
- (Optional) Mark the old overloads `[Obsolete]` if you want to guide users toward the new culture-aware overloads, but keep them for binary compatibility.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Test Results 42 files 42 suites 17m 53s ⏱️ Results for commit bf41159. |
|
Recreating from a clean branch based on dev. |



Summary
ErrorMessagenow says"The request timed out."instead of"A task was canceled."ErrorExceptionstill holds the originalTaskCanceledExceptionunchangedResponseStatus.TimedOut+ meaningfulErrorMessage+ originalErrorExceptionFixes #2257
Test plan
🤖 Generated with Claude Code