From dd7a096475dbae724eae5398f254700653f3b7e0 Mon Sep 17 00:00:00 2001 From: gekctek Date: Tue, 4 Feb 2025 06:44:58 -0800 Subject: [PATCH 1/2] Better error message for status response parsing --- src/Agent/Agents/HttpAgent.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Agent/Agents/HttpAgent.cs b/src/Agent/Agents/HttpAgent.cs index cf79ec5..fdf8eb6 100644 --- a/src/Agent/Agents/HttpAgent.cs +++ b/src/Agent/Agents/HttpAgent.cs @@ -299,7 +299,15 @@ public async Task GetReplicaStatusAsync( HttpResponse httpResponse = await this.httpClient.GetAsync("/api/v2/status", cancellationToken); await httpResponse.ThrowIfErrorAsync(); byte[] bytes = await httpResponse.GetContentAsync(); - return StatusResponse.ReadCbor(new CborReader(bytes)); + try + { + return StatusResponse.ReadCbor(new CborReader(bytes)); + } + catch (Exception ex) + { + string textResponse = Encoding.UTF8.GetString(bytes); + throw new Exception("Unable to parse status response CBOR.\nUTF-8 content: " + textResponse, ex); + } } private async Task<(HttpResponse Response, RequestId RequestId)> SendAsync( From be08d58813376f4a995295bd3c1b8da45411492e Mon Sep 17 00:00:00 2001 From: gekctek Date: Tue, 4 Feb 2025 07:10:28 -0800 Subject: [PATCH 2/2] Making ic_api_version optional --- src/Agent/API.xml | 2 +- src/Agent/Agents/HttpAgent.cs | 10 +--------- src/Agent/Responses/StatusResponse.cs | 11 +++-------- 3 files changed, 5 insertions(+), 18 deletions(-) diff --git a/src/Agent/API.xml b/src/Agent/API.xml index d38d926..b32fd7c 100644 --- a/src/Agent/API.xml +++ b/src/Agent/API.xml @@ -1206,7 +1206,7 @@ - Identifies the interface version supported, i.e. the version of the present + Optional. Identifies the interface version supported, i.e. the version of the present document that the internet computer aims to support, e.g. `0.8.1`. The implementation may also return unversioned to indicate that it does not comply to a particular version, e.g. in between releases. diff --git a/src/Agent/Agents/HttpAgent.cs b/src/Agent/Agents/HttpAgent.cs index fdf8eb6..cf79ec5 100644 --- a/src/Agent/Agents/HttpAgent.cs +++ b/src/Agent/Agents/HttpAgent.cs @@ -299,15 +299,7 @@ public async Task GetReplicaStatusAsync( HttpResponse httpResponse = await this.httpClient.GetAsync("/api/v2/status", cancellationToken); await httpResponse.ThrowIfErrorAsync(); byte[] bytes = await httpResponse.GetContentAsync(); - try - { - return StatusResponse.ReadCbor(new CborReader(bytes)); - } - catch (Exception ex) - { - string textResponse = Encoding.UTF8.GetString(bytes); - throw new Exception("Unable to parse status response CBOR.\nUTF-8 content: " + textResponse, ex); - } + return StatusResponse.ReadCbor(new CborReader(bytes)); } private async Task<(HttpResponse Response, RequestId RequestId)> SendAsync( diff --git a/src/Agent/Responses/StatusResponse.cs b/src/Agent/Responses/StatusResponse.cs index 637043f..da96838 100644 --- a/src/Agent/Responses/StatusResponse.cs +++ b/src/Agent/Responses/StatusResponse.cs @@ -14,7 +14,7 @@ public class StatusResponse /// The implementation may also return unversioned to indicate that it does not /// comply to a particular version, e.g. in between releases. /// - public string ICApiVersion { get; } + public string? ICApiVersion { get; } /// /// Optional. Identifies the implementation of the Internet Computer Protocol, @@ -44,7 +44,7 @@ public class StatusResponse /// public byte[]? DevelopmentRootKey { get; } - /// Identifies the interface version supported, i.e. the version of the present + /// Optional. Identifies the interface version supported, i.e. the version of the present /// document that the internet computer aims to support, e.g. `0.8.1`. /// The implementation may also return unversioned to indicate that it does not /// comply to a particular version, e.g. in between releases. @@ -61,7 +61,7 @@ public class StatusResponse /// Internet Computer, agents must have an independent trustworthy source for this data, /// and must not be tempted to fetch it from this insecure location public StatusResponse( - string icApiVersion, + string? icApiVersion, string? implementationSource, string? implementationVersion, string? implementationRevision, @@ -119,11 +119,6 @@ internal static StatusResponse ReadCbor(CborReader reader) reader.ReadEndMap(); - if (icApiVersion == null) - { - throw new CborContentException("Missing field: " + Properties.IC_API_VERSION); - } - return new StatusResponse(icApiVersion, implementationSource, implementationVersion, implementationRevision, developmentRootKey); }