From 9cf732cf0ab994fe04aa25cf89cfd448582c49c8 Mon Sep 17 00:00:00 2001 From: Veronica Giaudrone Date: Wed, 13 Jul 2016 14:08:05 -0700 Subject: [PATCH 1/2] Throw code generation error if return type for pageable operation doesn't contain a collection --- .../TemplateModels/AzureMethodTemplateModel.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/generator/AutoRest.Ruby.Azure/TemplateModels/AzureMethodTemplateModel.cs b/src/generator/AutoRest.Ruby.Azure/TemplateModels/AzureMethodTemplateModel.cs index bfec27ea09..db7ea4d64a 100644 --- a/src/generator/AutoRest.Ruby.Azure/TemplateModels/AzureMethodTemplateModel.cs +++ b/src/generator/AutoRest.Ruby.Azure/TemplateModels/AzureMethodTemplateModel.cs @@ -8,6 +8,7 @@ using System.Net; using System.Text; using AutoRest.Core.ClientModel; +using AutoRest.Core.Logging; using AutoRest.Extensions.Azure; using AutoRest.Extensions.Azure.Model; using AutoRest.Ruby.Azure.Properties; @@ -274,8 +275,15 @@ public override string OperationReturnTypeString { if (Extensions.ContainsKey("nextMethodName") && !Extensions.ContainsKey(AzureExtensions.PageableExtension)) { - SequenceType sequenceType = ((CompositeType)ReturnType.Body).Properties.Select(p => p.Type).FirstOrDefault(t => t is SequenceType) as SequenceType; - return string.Format(CultureInfo.InvariantCulture, "Array<{0}>", sequenceType.ElementType.Name); + try + { + SequenceType sequenceType = ((CompositeType)ReturnType.Body).Properties.Select(p => p.Type).FirstOrDefault(t => t is SequenceType) as SequenceType; + return string.Format(CultureInfo.InvariantCulture, "Array<{0}>", sequenceType.ElementType.Name); + } + catch (NullReferenceException nr) + { + throw ErrorManager.CreateError(nr, AutoRest.Core.Properties.Resources.CodeGenerationFailed, nr.Message); + } } return base.OperationReturnTypeString; } From 70e51148068bcd0f824cd0667e629fa3a3b4aa33 Mon Sep 17 00:00:00 2001 From: Veronica Giaudrone Date: Wed, 13 Jul 2016 16:24:47 -0700 Subject: [PATCH 2/2] addressing feedback --- .../TemplateModels/AzureMethodTemplateModel.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/generator/AutoRest.Ruby.Azure/TemplateModels/AzureMethodTemplateModel.cs b/src/generator/AutoRest.Ruby.Azure/TemplateModels/AzureMethodTemplateModel.cs index db7ea4d64a..0e5e6fea21 100644 --- a/src/generator/AutoRest.Ruby.Azure/TemplateModels/AzureMethodTemplateModel.cs +++ b/src/generator/AutoRest.Ruby.Azure/TemplateModels/AzureMethodTemplateModel.cs @@ -282,7 +282,7 @@ public override string OperationReturnTypeString } catch (NullReferenceException nr) { - throw ErrorManager.CreateError(nr, AutoRest.Core.Properties.Resources.CodeGenerationFailed, nr.Message); + throw ErrorManager.CreateError(string.Format(CultureInfo.InvariantCulture, "No collection type exists in pageable operation return type: {0}", nr.StackTrace)); } } return base.OperationReturnTypeString;