AB3267 - refactored new Exception(..) to most explicit exceptions
This commit is contained in:
@@ -186,11 +186,11 @@ namespace Umbraco.ModelsBuilder.Building
|
||||
foreach (var typeModel in _typeModels.Where(x => x.IsElement))
|
||||
{
|
||||
if (typeModel.BaseType != null && !typeModel.BaseType.IsElement)
|
||||
throw new Exception($"Cannot generate model for type '{typeModel.Alias}' because it is an element type, but its parent type '{typeModel.BaseType.Alias}' is not.");
|
||||
throw new InvalidOperationException($"Cannot generate model for type '{typeModel.Alias}' because it is an element type, but its parent type '{typeModel.BaseType.Alias}' is not.");
|
||||
|
||||
var errs = typeModel.MixinTypes.Where(x => !x.IsElement).ToList();
|
||||
if (errs.Count > 0)
|
||||
throw new Exception($"Cannot generate model for type '{typeModel.Alias}' because it is an element type, but it is composed of {string.Join(", ", errs.Select(x => "'" + x.Alias + "'"))} which {(errs.Count == 1 ? "is" : "are")} not.");
|
||||
throw new InvalidOperationException($"Cannot generate model for type '{typeModel.Alias}' because it is an element type, but it is composed of {string.Join(", ", errs.Select(x => "'" + x.Alias + "'"))} which {(errs.Count == 1 ? "is" : "are")} not.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Threading;
|
||||
using System.Web;
|
||||
using System.Web.Hosting;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Exceptions;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.ModelsBuilder.Configuration;
|
||||
using Umbraco.ModelsBuilder.Umbraco;
|
||||
@@ -103,7 +104,7 @@ namespace Umbraco.ModelsBuilder.Umbraco
|
||||
|
||||
var bin = HostingEnvironment.MapPath("~/bin");
|
||||
if (bin == null)
|
||||
throw new Exception("Panic: bin is null.");
|
||||
throw new PanicException("Panic: bin is null.");
|
||||
|
||||
// EnableDllModels will recycle the app domain - but this request will end properly
|
||||
ModelsBuilderBackOfficeController.GenerateModels(_umbracoServices, modelsDirectory, modelsNamespace);
|
||||
|
||||
@@ -56,17 +56,17 @@ namespace Umbraco.ModelsBuilder.Umbraco
|
||||
ServerVariablesParser.Parsing += (sender, serverVars) =>
|
||||
{
|
||||
if (!serverVars.ContainsKey("umbracoUrls"))
|
||||
throw new Exception("Missing umbracoUrls.");
|
||||
throw new ArgumentException("Missing umbracoUrls.");
|
||||
var umbracoUrlsObject = serverVars["umbracoUrls"];
|
||||
if (umbracoUrlsObject == null)
|
||||
throw new Exception("Null umbracoUrls");
|
||||
throw new ArgumentException("Null umbracoUrls");
|
||||
if (!(umbracoUrlsObject is Dictionary<string, object> umbracoUrls))
|
||||
throw new Exception("Invalid umbracoUrls");
|
||||
throw new ArgumentException("Invalid umbracoUrls");
|
||||
|
||||
if (!serverVars.ContainsKey("umbracoPlugins"))
|
||||
throw new Exception("Missing umbracoPlugins.");
|
||||
throw new ArgumentException("Missing umbracoPlugins.");
|
||||
if (!(serverVars["umbracoPlugins"] is Dictionary<string, object> umbracoPlugins))
|
||||
throw new Exception("Invalid umbracoPlugins");
|
||||
throw new ArgumentException("Invalid umbracoPlugins");
|
||||
|
||||
if (HttpContext.Current == null) throw new InvalidOperationException("HttpContext is null");
|
||||
var urlHelper = new UrlHelper(new RequestContext(new HttpContextWrapper(HttpContext.Current), new RouteData()));
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Exceptions;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Core.Services;
|
||||
@@ -88,7 +89,7 @@ namespace Umbraco.ModelsBuilder.Umbraco
|
||||
// of course this should never happen, but when it happens, better detect it
|
||||
// else we end up with weird nullrefs everywhere
|
||||
if (uniqueTypes.Contains(typeModel.ClrName))
|
||||
throw new Exception($"Panic: duplicate type ClrName \"{typeModel.ClrName}\".");
|
||||
throw new PanicException($"Panic: duplicate type ClrName \"{typeModel.ClrName}\".");
|
||||
uniqueTypes.Add(typeModel.ClrName);
|
||||
|
||||
var publishedContentType = _publishedContentTypeFactory.CreateContentType(contentType);
|
||||
@@ -128,7 +129,7 @@ namespace Umbraco.ModelsBuilder.Umbraco
|
||||
|
||||
var publishedPropertyType = publishedContentType.GetPropertyType(propertyType.Alias);
|
||||
if (publishedPropertyType == null)
|
||||
throw new Exception($"Panic: could not get published property type {contentType.Alias}.{propertyType.Alias}.");
|
||||
throw new PanicException($"Panic: could not get published property type {contentType.Alias}.{propertyType.Alias}.");
|
||||
|
||||
propertyModel.ModelClrType = publishedPropertyType.ModelClrType;
|
||||
|
||||
@@ -150,7 +151,7 @@ namespace Umbraco.ModelsBuilder.Umbraco
|
||||
foreach (var contentType in contentTypes)
|
||||
{
|
||||
var typeModel = typeModels.SingleOrDefault(x => x.Id == contentType.Id);
|
||||
if (typeModel == null) throw new Exception("Panic: no type model matching content type.");
|
||||
if (typeModel == null) throw new PanicException("Panic: no type model matching content type.");
|
||||
|
||||
IEnumerable<IContentTypeComposition> compositionTypes;
|
||||
var contentTypeAsMedia = contentType as IMediaType;
|
||||
@@ -159,12 +160,12 @@ namespace Umbraco.ModelsBuilder.Umbraco
|
||||
if (contentTypeAsMedia != null) compositionTypes = contentTypeAsMedia.ContentTypeComposition;
|
||||
else if (contentTypeAsContent != null) compositionTypes = contentTypeAsContent.ContentTypeComposition;
|
||||
else if (contentTypeAsMember != null) compositionTypes = contentTypeAsMember.ContentTypeComposition;
|
||||
else throw new Exception(string.Format("Panic: unsupported type \"{0}\".", contentType.GetType().FullName));
|
||||
else throw new PanicException(string.Format("Panic: unsupported type \"{0}\".", contentType.GetType().FullName));
|
||||
|
||||
foreach (var compositionType in compositionTypes)
|
||||
{
|
||||
var compositionModel = typeModels.SingleOrDefault(x => x.Id == compositionType.Id);
|
||||
if (compositionModel == null) throw new Exception("Panic: composition type does not exist.");
|
||||
if (compositionModel == null) throw new PanicException("Panic: composition type does not exist.");
|
||||
|
||||
if (compositionType.Id == contentType.ParentId) continue;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user