public void Handle(ErrorContext errorContext) { logger.Log(LogLevel.Error, "Persistent object deserialization error, will ignore and use defaults, error details: " + errorContext.GetErrorDetailsAsString(), "WurmApi", null); errorContext.Decision = Decision.IgnoreErrorsAndReturnDefaultsForMissingData; }
public Persistent <TEntity> GetObject() { var o = new Persistent <TEntity>(objectId); var data = persistenceStrategy.TryLoad(objectId, collectionId); if (data == null) { // data does not exist, return new with default return(o); } try { o.Entity = serializationStrategy.Deserialize <TEntity>(data); } catch (DeserializationErrorsException <TEntity> exception) { var errorContext = new ErrorContext(exception.Errors, persistenceStrategy, collectionId, objectId); objectDeserializationErrorHandlingStrategy.Handle(errorContext); if (errorContext.Decision == Decision.DoNotIgnoreAndRethrowTheException) { throw; } else if (errorContext.Decision == Decision.IgnoreErrorsAndReturnDefaultsForMissingData) { o.Entity = exception.DeserializedFallbackEntity; return(o); } else if (errorContext.Decision == Decision.RetryDeserialization) { throw new RetryException(); } else { throw new InvalidOperationException("Unknown Decision: " + errorContext.Decision); } } if (o.Entity.ObjectId != objectId) { var errorContext = new ErrorContext( new[] { new DeserializationErrorDetails() { DeserializationErrorKind = DeserializationErrorKind.ObjectIdMismatch } }, persistenceStrategy, collectionId, objectId); objectDeserializationErrorHandlingStrategy.Handle(errorContext); if (errorContext.Decision == Decision.DoNotIgnoreAndRethrowTheException) { throw new InvalidOperationException( string.Format( "Deserialized entity objectId {0} is different than requested objectId {1}", o.Entity.ObjectId, objectId)); } else if (errorContext.Decision == Decision.IgnoreErrorsAndReturnDefaultsForMissingData) { o.Entity.ObjectId = objectId; } else if (errorContext.Decision == Decision.RetryDeserialization) { throw new RetryException(); } else { throw new InvalidOperationException("Unknown Decision: " + errorContext.Decision); } } return(o); }
public void Handle(ErrorContext errorContext) { // do nothing, return default decision }
public void Handle(ErrorContext errorContext) { action(errorContext); }