diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithydotnet/ServiceCodegen.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithydotnet/ServiceCodegen.java index 7f0986b93..d3ad8e3a8 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithydotnet/ServiceCodegen.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithydotnet/ServiceCodegen.java @@ -91,9 +91,11 @@ public Map generate() { final Path collectionOfErrorsPath = Path.of("CollectionOfErrors.cs"); final TokenTree collectionOfErrorsPathCode = generateCollectionExceptionClass(); + final TokenTree genericImport = TokenTree.of("using System.Collections.Generic;"); + codeByPath.put( collectionOfErrorsPath, - collectionOfErrorsPathCode.prepend(prelude) + collectionOfErrorsPathCode.prepend(prelude).prepend(genericImport) ); // Opaque exception class @@ -329,9 +331,17 @@ public TokenTree generateCollectionExceptionClass() { """ public class CollectionOfErrors : Exception { public readonly System.Collections.Generic.List list; - public CollectionOfErrors(System.Collections.Generic.List list, string message) : base(message) { this.list = list; } + public CollectionOfErrors(System.Collections.Generic.List 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(); } public CollectionOfErrors() : base("CollectionOfErrors") { this.list = new System.Collections.Generic.List(); } + private static string ListAsString(List 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); + } } """ )