diff --git a/uSync.Core/Serialization/Serializers/ContentSerializer.cs b/uSync.Core/Serialization/Serializers/ContentSerializer.cs index b530f8fd..b63d34da 100644 --- a/uSync.Core/Serialization/Serializers/ContentSerializer.cs +++ b/uSync.Core/Serialization/Serializers/ContentSerializer.cs @@ -165,7 +165,15 @@ public override Task SaveWithSchedulesAsync(IContent item, int } public override Task SaveAsync(IEnumerable items) - => Task.FromResult(contentService.Save(items)); + => uSyncTaskHelper.FromResultOf(() => + { + var result = contentService.Save(items); + if (result.Success is false) + { + throw new InvalidOperationException( + $"Could not save content items: {result.Result}"); + } + }); public override async Task SaveItemAsync(IContent item) => await SaveItemAsync(item, -1); @@ -184,11 +192,16 @@ public override Task SaveItemAsync(IContent item, int userId) { try { - contentService.Save(item, userId); + var result = contentService.Save(item, userId); + if (result.Success is false) + { + throw new InvalidOperationException( + $"Could not save content {item.Name}: {result.Result}"); + } } catch (ArgumentNullException ex) { - // we can get thrown a null argument exception by the notifier, + // we can get thrown a null argument exception by the notifier, // which is non critical! but we are ignoring this error. ! <= 8.1.5 if (!ex.Message.Contains("siteUri")) throw; } diff --git a/uSync.Core/Serialization/Serializers/ContentTypeBaseSerializer.cs b/uSync.Core/Serialization/Serializers/ContentTypeBaseSerializer.cs index e6a3f225..5930c4d0 100644 --- a/uSync.Core/Serialization/Serializers/ContentTypeBaseSerializer.cs +++ b/uSync.Core/Serialization/Serializers/ContentTypeBaseSerializer.cs @@ -1352,13 +1352,14 @@ public override async Task SaveItemAsync(TObject item) return; } - if (item.Id <= 0) - { - await _baseService.CreateAsync(item, Constants.Security.SuperUserKey); - } - else + var attempt = item.Id <= 0 + ? await _baseService.CreateAsync(item, Constants.Security.SuperUserKey) + : await _baseService.UpdateAsync(item, Constants.Security.SuperUserKey); + + if (attempt.Success is false) { - await _baseService.UpdateAsync(item, Constants.Security.SuperUserKey); + throw new InvalidOperationException( + $"Could not save {typeof(TObject).Name} {item.Alias}: {attempt.Result}"); } //if (item.IsDirty()) _baseService.Save(item); diff --git a/uSync.Core/Serialization/Serializers/ContentTypeSerializer.cs b/uSync.Core/Serialization/Serializers/ContentTypeSerializer.cs index 7d2bf95d..59227e48 100644 --- a/uSync.Core/Serialization/Serializers/ContentTypeSerializer.cs +++ b/uSync.Core/Serialization/Serializers/ContentTypeSerializer.cs @@ -206,7 +206,12 @@ public override async Task> DeserializeSecondPassAsync if (logger.IsEnabled(LogLevel.Debug)) logger.LogDebug("Saving in Serializer because item is dirty [{properties}]", dirty); - await _contentTypeService.UpdateAsync(item, Constants.Security.SuperUserKey); + var attempt = await _contentTypeService.UpdateAsync(item, Constants.Security.SuperUserKey); + if (attempt.Success is false) + { + throw new InvalidOperationException( + $"Could not save content type {item.Alias}: {attempt.Result}"); + } } await CleanFolderAsync(item, node); diff --git a/uSync.Core/Serialization/Serializers/DataTypeSerializer.cs b/uSync.Core/Serialization/Serializers/DataTypeSerializer.cs index 2feb00c7..7622ace4 100644 --- a/uSync.Core/Serialization/Serializers/DataTypeSerializer.cs +++ b/uSync.Core/Serialization/Serializers/DataTypeSerializer.cs @@ -368,10 +368,15 @@ public override async Task SaveItemAsync(IDataType item) // see : https://github.com/umbraco/Umbraco-CMS/issues/19732 // if (item.IsDirty() is false) return; - if (item.HasIdentity is true) - await _dataTypeService.UpdateAsync(item, Constants.Security.SuperUserKey); - else - await _dataTypeService.CreateAsync(item, Constants.Security.SuperUserKey); + var attempt = item.HasIdentity is true + ? await _dataTypeService.UpdateAsync(item, Constants.Security.SuperUserKey) + : await _dataTypeService.CreateAsync(item, Constants.Security.SuperUserKey); + + if (attempt.Success is false) + { + throw new InvalidOperationException( + $"Could not save data type {item.Name}: {attempt.Status}"); + } } public override async Task SaveAsync(IEnumerable items) diff --git a/uSync.Core/Serialization/Serializers/DomainSerializer.cs b/uSync.Core/Serialization/Serializers/DomainSerializer.cs index 3b456f72..694eddbe 100644 --- a/uSync.Core/Serialization/Serializers/DomainSerializer.cs +++ b/uSync.Core/Serialization/Serializers/DomainSerializer.cs @@ -342,7 +342,12 @@ public override async Task SaveItemAsync(IDomain item) }) }; - await _domainService.UpdateDomainsAsync(contentKey.Result, updateModel); + var attempt = await _domainService.UpdateDomainsAsync(contentKey.Result, updateModel); + if (attempt.Success is false) + { + throw new InvalidOperationException( + $"Could not save domain {item.DomainName}: {attempt.Status}"); + } } private sealed class DomainSyncModel @@ -362,7 +367,12 @@ public override async Task DeleteItemAsync(IDomain item) var existing = await _domainService.GetAssignedDomainsAsync(contentKey.Result, true); var remaining = existing.Where(x => x.Key != item.Key).Select(x => new DomainModel { DomainName = x.DomainName, IsoCode = x.LanguageIsoCode! }); - await _domainService.UpdateDomainsAsync(contentKey.Result, new DomainsUpdateModel { Domains = remaining }); + var attempt = await _domainService.UpdateDomainsAsync(contentKey.Result, new DomainsUpdateModel { Domains = remaining }); + if (attempt.Success is false) + { + throw new InvalidOperationException( + $"Could not remove domain {item.DomainName}: {attempt.Status}"); + } } public override string ItemAlias(IDomain item) diff --git a/uSync.Core/Serialization/Serializers/MediaSerializer.cs b/uSync.Core/Serialization/Serializers/MediaSerializer.cs index c122fef5..099fd11b 100644 --- a/uSync.Core/Serialization/Serializers/MediaSerializer.cs +++ b/uSync.Core/Serialization/Serializers/MediaSerializer.cs @@ -230,13 +230,37 @@ private static string GetFilePath(string? value) } public override Task SaveAsync(IEnumerable items) - => uSyncTaskHelper.FromResultOf(() => { return _mediaService.Save(items); }); + => uSyncTaskHelper.FromResultOf(() => + { + var attempt = _mediaService.Save(items); + if (attempt.Success is false) + { + throw new InvalidOperationException( + $"Could not save media items: {attempt.Result?.Result}"); + } + }); public override Task SaveItemAsync(IMedia item) - => uSyncTaskHelper.FromResultOf(() => { return _mediaService.Save(item); }); + => uSyncTaskHelper.FromResultOf(() => + { + var attempt = _mediaService.Save(item); + if (attempt.Success is false) + { + throw new InvalidOperationException( + $"Could not save media {item.Name}: {attempt.Result?.Result}"); + } + }); public override Task DeleteItemAsync(IMedia item) - => uSyncTaskHelper.FromResultOf(() => { return _mediaService.Delete(item); }); + => uSyncTaskHelper.FromResultOf(() => + { + var attempt = _mediaService.Delete(item); + if (attempt.Success is false) + { + throw new InvalidOperationException( + $"Could not delete media {item.Name}: {attempt.Result?.Result}"); + } + }); protected override Task FindParentByIdAsync(int id) { diff --git a/uSync.Core/Serialization/Serializers/TemplateSerializer.cs b/uSync.Core/Serialization/Serializers/TemplateSerializer.cs index 2c2fa522..3061abef 100644 --- a/uSync.Core/Serialization/Serializers/TemplateSerializer.cs +++ b/uSync.Core/Serialization/Serializers/TemplateSerializer.cs @@ -355,9 +355,15 @@ public override async Task SaveItemAsync(ITemplate item) logger.LogDebug("Saving: {alias} {path}", item.Alias, item.Path); var result = await _templateService.UpdateAsync(item, userKey); - + if (logger.IsEnabled(LogLevel.Debug)) logger.LogDebug("Update Template Result: [{key}] {result} {status}", item.Key, result.Success, result.Status); + + if (result.Success is false) + { + throw new InvalidOperationException( + $"Could not save template {item.Alias}: {result.Status}"); + } } else { @@ -365,9 +371,15 @@ public override async Task SaveItemAsync(ITemplate item) logger.LogDebug("Creating: {alias} {path}", item.Alias, item.Path); var result = await _templateService.CreateAsync(item.Name ?? item.Alias, item.Alias, item.Content, userKey, item.Key); - + if (logger.IsEnabled(LogLevel.Debug)) logger.LogDebug("Update Template Result: [{key}] {result} {status}", item.Key, result.Success, result.Status); + + if (result.Success is false) + { + throw new InvalidOperationException( + $"Could not save template {item.Alias}: {result.Status}"); + } } }