Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(.NET): Improve Collection of Errors string #1158

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
diff --git b/AwsCryptographicMaterialProviders/runtimes/net/Generated/AwsCryptographicMaterialProviders/CollectionOfErrors.cs a/AwsCryptographicMaterialProviders/runtimes/net/Generated/AwsCryptographicMaterialProviders/CollectionOfErrors.cs
index 8f7200422..39f044046 100644
--- b/AwsCryptographicMaterialProviders/runtimes/net/Generated/AwsCryptographicMaterialProviders/CollectionOfErrors.cs
+++ a/AwsCryptographicMaterialProviders/runtimes/net/Generated/AwsCryptographicMaterialProviders/CollectionOfErrors.cs
@@ -8,9 +8,18 @@ namespace AWS.Cryptography.MaterialProviders
public class CollectionOfErrors : Exception
{
public readonly System.Collections.Generic.List<Exception> list;
- public CollectionOfErrors(System.Collections.Generic.List<Exception> list, string message) : base(message) { this.list = list; }
+ public CollectionOfErrors(System.Collections.Generic.List<Exception> list, string message) : base(message + $"\n List: \n{ListAsString(list)}") { this.list = list; }
public CollectionOfErrors(string message) : base(message) { this.list = new System.Collections.Generic.List<Exception>(); }
public CollectionOfErrors() : base("CollectionOfErrors") { this.list = new System.Collections.Generic.List<Exception>(); }
+
+ private static string ListAsString(List<Exception> list)
+ {
+ if (list.Count < 1) return "";
+ string[] msgArr = new string[list.Count];
+ for (int i = 0; i < list.Count; i++)
+ msgArr[i] = $"{list[i].GetType().Name} :: {list[i].Message}";
+ return String.Join("\n\t", msgArr);
+ }
}

}
diff --git b/AwsCryptographicMaterialProviders/runtimes/net/Generated/AwsCryptographicMaterialProviders/TypeConversion.cs a/AwsCryptographicMaterialProviders/runtimes/net/Generated/AwsCryptographicMaterialProviders/TypeConversion.cs
index d5ab49915..446365249 100644
--- b/AwsCryptographicMaterialProviders/runtimes/net/Generated/AwsCryptographicMaterialProviders/TypeConversion.cs
+++ a/AwsCryptographicMaterialProviders/runtimes/net/Generated/AwsCryptographicMaterialProviders/TypeConversion.cs
@@ -3946,7 +3946,9 @@ namespace AWS.Cryptography.MaterialProviders
dafnyVal._ComAmazonawsDynamodb
);
case software.amazon.cryptography.materialproviders.internaldafny.types.Error_ComAmazonawsKms dafnyVal:
- return Com.Amazonaws.KMS.TypeConversion.FromDafny_CommonError(
+ // BEGIN MANUAL EDIT
+ return Com.Amazonaws.Kms.TypeConversion.FromDafny_CommonError(
+ // END MANUAL EDIT
dafnyVal._ComAmazonawsKms
);
case software.amazon.cryptography.materialproviders.internaldafny.types.Error_AwsCryptographicMaterialProvidersException dafnyVal:
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
diff --git b/AwsCryptographicMaterialProviders/runtimes/net/Generated/AwsCryptographyKeyStore/CollectionOfErrors.cs a/AwsCryptographicMaterialProviders/runtimes/net/Generated/AwsCryptographyKeyStore/CollectionOfErrors.cs
index e752a715a..e203599b2 100644
--- b/AwsCryptographicMaterialProviders/runtimes/net/Generated/AwsCryptographyKeyStore/CollectionOfErrors.cs
+++ a/AwsCryptographicMaterialProviders/runtimes/net/Generated/AwsCryptographyKeyStore/CollectionOfErrors.cs
@@ -8,9 +8,17 @@ namespace AWS.Cryptography.KeyStore
public class CollectionOfErrors : Exception
{
public readonly System.Collections.Generic.List<Exception> list;
- public CollectionOfErrors(System.Collections.Generic.List<Exception> list, string message) : base(message) { this.list = list; }
+ public CollectionOfErrors(System.Collections.Generic.List<Exception> list, string message) : base(message + $"\n List: \n{ListAsString(list)}") { this.list = list; }
public CollectionOfErrors(string message) : base(message) { this.list = new System.Collections.Generic.List<Exception>(); }
public CollectionOfErrors() : base("CollectionOfErrors") { this.list = new System.Collections.Generic.List<Exception>(); }
- }

+ private static string ListAsString(List<Exception> list)
+ {
+ if (list.Count < 1) return "";
+ string[] msgArr = new string[list.Count];
+ for (int i = 0; i < list.Count; i++)
+ msgArr[i] = $"{list[i].GetType().Name} :: {list[i].Message}";
+ return String.Join("\n\t", msgArr);
+ }
+ }
}
diff --git b/AwsCryptographicMaterialProviders/runtimes/net/Generated/AwsCryptographyKeyStore/TypeConversion.cs a/AwsCryptographicMaterialProviders/runtimes/net/Generated/AwsCryptographyKeyStore/TypeConversion.cs
index b7ee7eb89..9c9b351d5 100644
--- b/AwsCryptographicMaterialProviders/runtimes/net/Generated/AwsCryptographyKeyStore/TypeConversion.cs
+++ a/AwsCryptographicMaterialProviders/runtimes/net/Generated/AwsCryptographyKeyStore/TypeConversion.cs
@@ -736,7 +736,9 @@ namespace AWS.Cryptography.KeyStore
dafnyVal._ComAmazonawsDynamodb
);
case software.amazon.cryptography.keystore.internaldafny.types.Error_ComAmazonawsKms dafnyVal:
- return Com.Amazonaws.KMS.TypeConversion.FromDafny_CommonError(
+ // BEGIN MANUAL EDIT
+ return Com.Amazonaws.Kms.TypeConversion.FromDafny_CommonError(
+ // END MANUAL EDIT
dafnyVal._ComAmazonawsKms
);
case software.amazon.cryptography.keystore.internaldafny.types.Error_KeyStoreException dafnyVal:
@@ -761,7 +763,9 @@ namespace AWS.Cryptography.KeyStore
{
case "Com.Amazonaws.KMS":
return software.amazon.cryptography.keystore.internaldafny.types.Error.create_ComAmazonawsKms(
- Com.Amazonaws.KMS.TypeConversion.ToDafny_CommonError(value)
+ // BEGIN MANUAL EDIT
+ Com.Amazonaws.Kms.TypeConversion.ToDafny_CommonError(value)
+ // END MANUAL EDIT
);
case "Com.Amazonaws.Dynamodb":
return software.amazon.cryptography.keystore.internaldafny.types.Error.create_ComAmazonawsDynamodb(
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,18 @@ namespace AWS.Cryptography.MaterialProviders
public class CollectionOfErrors : Exception
{
public readonly System.Collections.Generic.List<Exception> list;
public CollectionOfErrors(System.Collections.Generic.List<Exception> list, string message) : base(message) { this.list = list; }
public CollectionOfErrors(System.Collections.Generic.List<Exception> list, string message) : base(message + $"\n List: \n{ListAsString(list)}") { this.list = list; }
public CollectionOfErrors(string message) : base(message) { this.list = new System.Collections.Generic.List<Exception>(); }
public CollectionOfErrors() : base("CollectionOfErrors") { this.list = new System.Collections.Generic.List<Exception>(); }

private static string ListAsString(List<Exception> list)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are not importing System.Collections.Generic.List

Suggested change
private static string ListAsString(List<Exception> list)
private static string ListAsString(System.Collections.Generic.List<Exception> list)

Here and other places

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@rishav-karanjit rishav-karanjit Jan 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are missing a import here. Thats why its a blocking comment.

For example: when I try to run this (below) it works but if I remove using System.Collections.Generic it will give me an error.

using System;
using System.Collections.Generic;

public class HelloWorld
{
    public static void Main(string[] args)
    {
        // Create a new List of strings
        List<string> names = new List<string>();

        // Add items to the list
        names.Add("Alice");
        names.Add("Bob");
        names.Add("Charlie");

        // Print all items in the list
        Console.WriteLine("All names:");
        foreach (string name in names)
        {
            Console.WriteLine(name);
        }
    }
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I guess the CI is passing because it only checks for output.Failure? but not output.error.TypeOfError?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you nailed it.
I got it to work for one of the three PRs, and did not verify across all three repos.

Great catch.

{
if (list.Count < 1) return "";
string[] msgArr = new string[list.Count];
for (int i = 0; i < list.Count; i++)
msgArr[i] = $"{list[i].GetType().Name} :: {list[i].Message}";
return String.Join("\n\t", msgArr);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,17 @@ namespace AWS.Cryptography.KeyStore
public class CollectionOfErrors : Exception
{
public readonly System.Collections.Generic.List<Exception> list;
public CollectionOfErrors(System.Collections.Generic.List<Exception> list, string message) : base(message) { this.list = list; }
public CollectionOfErrors(System.Collections.Generic.List<Exception> list, string message) : base(message + $"\n List: \n{ListAsString(list)}") { this.list = list; }
public CollectionOfErrors(string message) : base(message) { this.list = new System.Collections.Generic.List<Exception>(); }
public CollectionOfErrors() : base("CollectionOfErrors") { this.list = new System.Collections.Generic.List<Exception>(); }
}

private static string ListAsString(List<Exception> list)
{
if (list.Count < 1) return "";
string[] msgArr = new string[list.Count];
for (int i = 0; i < list.Count; i++)
msgArr[i] = $"{list[i].GetType().Name} :: {list[i].Message}";
return String.Join("\n\t", msgArr);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
diff --git b/AwsCryptographyPrimitives/runtimes/net/Generated/CollectionOfErrors.cs a/AwsCryptographyPrimitives/runtimes/net/Generated/CollectionOfErrors.cs
index ed41bb43b..1df996dd0 100644
--- b/AwsCryptographyPrimitives/runtimes/net/Generated/CollectionOfErrors.cs
+++ a/AwsCryptographyPrimitives/runtimes/net/Generated/CollectionOfErrors.cs
@@ -8,9 +8,18 @@ namespace AWS.Cryptography.Primitives
public class CollectionOfErrors : Exception
{
public readonly System.Collections.Generic.List<Exception> list;
- public CollectionOfErrors(System.Collections.Generic.List<Exception> list, string message) : base(message) { this.list = list; }
+ public CollectionOfErrors(System.Collections.Generic.List<Exception> list, string message) : base(message + $"\n List: \n{ListAsString(list)}") { this.list = list; }
public CollectionOfErrors(string message) : base(message) { this.list = new System.Collections.Generic.List<Exception>(); }
public CollectionOfErrors() : base("CollectionOfErrors") { this.list = new System.Collections.Generic.List<Exception>(); }
+
+ private static string ListAsString(List<Exception> list)
+ {
+ if (list.Count < 1) return "";
+ string[] msgArr = new string[list.Count];
+ for (int i = 0; i < list.Count; i++)
+ msgArr[i] = $"{list[i].GetType().Name} :: {list[i].Message}";
+ return String.Join("\n\t", msgArr);
+ }
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,18 @@ namespace AWS.Cryptography.Primitives
public class CollectionOfErrors : Exception
{
public readonly System.Collections.Generic.List<Exception> list;
public CollectionOfErrors(System.Collections.Generic.List<Exception> list, string message) : base(message) { this.list = list; }
public CollectionOfErrors(System.Collections.Generic.List<Exception> list, string message) : base(message + $"\n List: \n{ListAsString(list)}") { this.list = list; }
public CollectionOfErrors(string message) : base(message) { this.list = new System.Collections.Generic.List<Exception>(); }
public CollectionOfErrors() : base("CollectionOfErrors") { this.list = new System.Collections.Generic.List<Exception>(); }

private static string ListAsString(List<Exception> list)
{
if (list.Count < 1) return "";
string[] msgArr = new string[list.Count];
for (int i = 0; i < list.Count; i++)
msgArr[i] = $"{list[i].GetType().Name} :: {list[i].Message}";
return String.Join("\n\t", msgArr);
}
}

}
Loading