Skip to content

Commit 1b851e1

Browse files
authored
fix(dotnet/runtime): Incorrect callback response format (#286)
The response for a callback completion that resulted in an error should use the `err` field name and not the `error` field name as was initially done. Additionally, the program flow did not propagate all errors back to the `jsii-kernel`, causing false-pass on the compliance test suite, as expectations were incorrectly set up to expect `RuntimeException` instead of `JsiiException`. Fixes #285
1 parent 100f5ad commit 1b851e1

File tree

5 files changed

+17
-18
lines changed

5 files changed

+17
-18
lines changed

fetch-dotnet-snk.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function echo_usage() {
1111
echo -e "\tDOTNET_STRONG_NAME_SECRET_ID=<The name (i.e. production/my/key) or ARN of the secret containing the .snk file.>"
1212
}
1313

14-
if [ -z ${DOTNET_STRONG_NAME_ENABLED:-} ]; then
14+
if [ -z "${DOTNET_STRONG_NAME_ENABLED:-}" ]; then
1515
echo "Environment variable DOTNET_STRONG_NAME_ENABLED is not set. Skipping strong-name signing."
1616
exit 0
1717
fi
@@ -21,19 +21,19 @@ echo "Retrieving SNK..."
2121
apt update -y
2222
apt install jq -y
2323

24-
if [ -z ${DOTNET_STRONG_NAME_ROLE_ARN:-} ]; then
24+
if [ -z "${DOTNET_STRONG_NAME_ROLE_ARN:-}" ]; then
2525
echo "Strong name signing is enabled, but DOTNET_STRONG_NAME_ROLE_ARN is not set."
2626
echo_usage
2727
exit 1
2828
fi
2929

30-
if [ -z ${DOTNET_STRONG_NAME_SECRET_REGION:-}]; then
30+
if [ -z "${DOTNET_STRONG_NAME_SECRET_REGION:-}" ]; then
3131
echo "Strong name signing is enabled, but DOTNET_STRONG_NAME_SECRET_REGION is not set."
3232
echo_usage
3333
exit 1
3434
fi
3535

36-
if [ -z ${DOTNET_STRONG_NAME_SECRET_ID:-} ]; then
36+
if [ -z "${DOTNET_STRONG_NAME_SECRET_ID:-}" ]; then
3737
echo "Strong name signing is enabled, but DOTNET_STRONG_NAME_SECRET_ID is not set."
3838
echo_usage
3939
exit 1

packages/jsii-dotnet-jsonmodel/src/Amazon.JSII.JsonModel/Api/Request/CompleteRequest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ public CompleteRequest(string callbackId, string error = null, object result = n
1919
[JsonProperty("cbid")]
2020
public string CallbackId { get; }
2121

22-
[JsonProperty("error", NullValueHandling = NullValueHandling.Ignore)]
22+
[JsonProperty("err", NullValueHandling = NullValueHandling.Ignore)]
2323
public string Error { get; }
2424

2525
[JsonProperty("result", NullValueHandling = NullValueHandling.Ignore)]
2626
public object Result { get; }
2727
}
28-
}
28+
}

packages/jsii-dotnet-runtime-test/test/Amazon.JSII.Runtime.IntegrationTests/ComplianceTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,8 @@ public void AsyncOverrides_OverrideThrows()
462462
{
463463
AsyncVirtualMethodsChild obj = new AsyncVirtualMethodsChild();
464464

465-
RuntimeException exception = Assert.Throws<RuntimeException>(() => obj.CallMe());
466-
Assert.Equal("Thrown by native code", exception.Message);
465+
JsiiException exception = Assert.Throws<JsiiException>(() => obj.CallMe());
466+
Assert.Contains("Thrown by native code", exception.Message);
467467
}
468468

469469
class SyncVirtualMethodsChild_Set_CallsSuper : SyncVirtualMethods
@@ -531,8 +531,8 @@ public void PropertyOverrides_Get_Throws()
531531
{
532532
SyncVirtualMethodsChild_Throws so = new SyncVirtualMethodsChild_Throws();
533533

534-
RuntimeException exception = Assert.Throws<RuntimeException>(() => so.RetrieveValueOfTheProperty());
535-
Assert.Equal("Oh no, this is bad", exception.Message);
534+
JsiiException exception = Assert.Throws<JsiiException>(() => so.RetrieveValueOfTheProperty());
535+
Assert.Contains("Oh no, this is bad", exception.Message);
536536
}
537537

538538
[Fact(DisplayName = Prefix + nameof(PropertyOverrides_Set_CallsSuper))]
@@ -549,8 +549,8 @@ public void PropertyOverrides_Set_Throws()
549549
{
550550
SyncVirtualMethodsChild_Throws so = new SyncVirtualMethodsChild_Throws();
551551

552-
RuntimeException exception = Assert.Throws<RuntimeException>(() => so.ModifyValueOfTheProperty("Hii"));
553-
Assert.Equal("Exception from overloaded setter", exception.Message);
552+
JsiiException exception = Assert.Throws<JsiiException>(() => so.ModifyValueOfTheProperty("Hii"));
553+
Assert.Contains("Exception from overloaded setter", exception.Message);
554554
}
555555

556556
[Fact(DisplayName = Prefix + nameof(PropertyOverrides_Interfaces))]

packages/jsii-dotnet-runtime/src/Amazon.JSII.Runtime/CallbackExtensions.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,13 @@ out object result
2929
}
3030
catch (TargetInvocationException e)
3131
{
32-
throw e.InnerException;
33-
}
34-
catch (TargetParameterCountException)
35-
{
36-
throw;
32+
// An exception was thrown by the method being invoked
33+
error = e.InnerException.ToString();
34+
return null;
3735
}
3836
catch (Exception e)
3937
{
38+
// An exception was thrown while preparing the request or processing the result
4039
error = e.ToString();
4140
return null;
4241
}

packages/jsii-dotnet-runtime/src/Amazon.JSII.Runtime/Deputy/DeputyBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ Func<IClient, object[], InvokeResponse> invokeFunc
251251
)
252252
{
253253
IServiceProvider serviceProvider = ServiceContainer.ServiceProvider;
254-
IClient client = serviceProvider.GetRequiredService<IClient>(); ;
254+
IClient client = serviceProvider.GetRequiredService<IClient>();
255255
IJsiiToFrameworkConverter converter = serviceProvider.GetRequiredService<IJsiiToFrameworkConverter>();
256256
IReferenceMap referenceMap = serviceProvider.GetRequiredService<IReferenceMap>();
257257

0 commit comments

Comments
 (0)