Skip to content

Commit

Permalink
new MartenException base class for all exception types in Marten. Closes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy D. Miller authored and jeremydmiller committed Jun 3, 2022
1 parent 28ecee1 commit d30755c
Show file tree
Hide file tree
Showing 31 changed files with 88 additions and 29 deletions.
2 changes: 1 addition & 1 deletion docs/configuration/multitenancy.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public interface ITenancy : IDatabaseSource
ValueTask<IMartenDatabase> FindOrCreateDatabase(string tenantIdOrDatabaseIdentifier);
}
```
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/Marten/Storage/ITenancy.cs#L8-L50' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_itenancy' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/Marten/Storage/ITenancy.cs#L9-L51' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_itenancy' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Assuming that we have a custom `ITenancy` model:
Expand Down
28 changes: 28 additions & 0 deletions src/CoreTests/all_exceptions_should_derive_from_MartenException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Baseline;
using LamarCodeGeneration;
using Marten.Events.TestSupport;
using Marten.Exceptions;
using Shouldly;
using Xunit;

namespace CoreTests
{
public class all_exceptions_should_derive_from_MartenException
{
[Fact]
public void all_exceptions_types()
{
var ignoredTypes = new Type[] { typeof(ProjectionScenarioException), typeof(MartenException), typeof(FastExpressionCompiler.NotSupportedExpressionException) };

var exceptionTypes = typeof(MartenException).Assembly.GetTypes()
.Where(x => x.CanBeCastTo(typeof(Exception)) && !x.CanBeCastTo(typeof(MartenException)) &&
!ignoredTypes.Contains(x)).ToList();

exceptionTypes.ShouldBeEmpty(exceptionTypes.Select(x => x.NameInCode()).Join(", "));

}
}
}
3 changes: 2 additions & 1 deletion src/Marten/Events/Daemon/EventFetcherException.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using System;
using Marten.Exceptions;
using Marten.Storage;

namespace Marten.Events.Daemon
{
/// <summary>
/// Marten failed to load events for a projection shard
/// </summary>
public class EventFetcherException: Exception
public class EventFetcherException: MartenException
{
public EventFetcherException(ShardName name, IMartenDatabase martenDatabase, Exception innerException) : base($"Failure while trying to load events for projection shard '{name}@{martenDatabase.Identifier}'", innerException)
{
Expand Down
3 changes: 2 additions & 1 deletion src/Marten/Events/Daemon/ShardStartException.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System;
using Marten.Exceptions;

namespace Marten.Events.Daemon
{
/// <summary>
/// A projection shard failed to start
/// </summary>
public class ShardStartException : Exception
public class ShardStartException : MartenException
{
internal ShardStartException(ShardAgent agent, Exception innerException) : base($"Failure while trying to stop '{agent.ProjectionShardIdentity}'", innerException)
{
Expand Down
3 changes: 2 additions & 1 deletion src/Marten/Events/Daemon/ShardStopException.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System;
using Marten.Exceptions;

namespace Marten.Events.Daemon
{
/// <summary>
/// A projection shard failed to stop in a timely manner
/// </summary>
public class ShardStopException : Exception
public class ShardStopException : MartenException
{
public ShardStopException(ShardName name, Exception innerException) : base($"Failure while trying to stop '{name.Identity}'", innerException)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Marten.Exceptions
{
public class AmbiguousDocumentTypeAliasesException: Exception
public class AmbiguousDocumentTypeAliasesException: MartenException
{
public AmbiguousDocumentTypeAliasesException(string message) : base(message)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Marten/Exceptions/ApplyEventException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Marten.Exceptions
{
public class ApplyEventException : Exception
public class ApplyEventException : MartenException
{
public ApplyEventException(IEvent @event, Exception innerException) : base($"Failure to apply event #{@event.Sequence} ({@event.Data}.)", innerException)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Marten/Exceptions/BadLinqExpressionException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Marten.Exceptions
[Serializable]
#endif

public class BadLinqExpressionException: Exception
public class BadLinqExpressionException: MartenException
{
public BadLinqExpressionException(string message, Exception innerException) : base(message, innerException)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Marten/Exceptions/ConcurrencyException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Marten.Exceptions
{
public class ConcurrencyException: Exception
public class ConcurrencyException: MartenException
{
public string DocType { get; set; }
public object Id { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion src/Marten/Exceptions/ConcurrentUpdateException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Marten.Exceptions
{
public class ConcurrentUpdateException: Exception
public class ConcurrentUpdateException: MartenException
{
public ConcurrentUpdateException(Exception innerException) : base("Write collision detected while commiting the transaction.", innerException)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Marten.Exceptions
{
public class DefaultTenantUsageDisabledException : Exception
public class DefaultTenantUsageDisabledException : MartenException
{
public DefaultTenantUsageDisabledException()
: base($"Default tenant {Tenancy.DefaultTenantId} usage is disabled. Ensure to create a session by explicitly passing a non-default tenant in the method arg or SessionOptions.")
Expand Down
2 changes: 1 addition & 1 deletion src/Marten/Exceptions/DocumentAlreadyExistsException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Marten.Exceptions
{
public sealed class DocumentAlreadyExistsException: Exception
public sealed class DocumentAlreadyExistsException: MartenException
{
public Type DocType { get; }
public object Id { get; }
Expand Down
2 changes: 1 addition & 1 deletion src/Marten/Exceptions/DocumentIdTypeMismatchException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Marten.Exceptions
{
public class DocumentIdTypeMismatchException : Exception
public class DocumentIdTypeMismatchException : MartenException
{
public DocumentIdTypeMismatchException(IDocumentStorage storage, Type actualIdType) : base($"Id/Document type mismatch. The id type for the included document type {storage.SourceType.FullNameInCode()} is {storage.IdType.FullNameInCode()}, but {actualIdType.NameInCode()} was used.")
{
Expand Down
2 changes: 1 addition & 1 deletion src/Marten/Exceptions/EmptyEventStreamException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Marten.Exceptions
{
public class EmptyEventStreamException : Exception
public class EmptyEventStreamException : MartenException
{
public static readonly string MessageTemplate =
"A new event stream ('{0}') cannot be started without any events";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Marten.Exceptions
{
public class ExistingStreamIdCollisionException: Exception
public class ExistingStreamIdCollisionException: MartenException
{
public object Id { get; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Marten.Exceptions
{
public class HiloSequenceAdvanceToNextHiAttemptsExceededException : Exception
public class HiloSequenceAdvanceToNextHiAttemptsExceededException : MartenException
{
private const string message = "Advance to next hilo sequence retry limit exceeded. Unable to secure next hi sequence";
public HiloSequenceAdvanceToNextHiAttemptsExceededException() : base(message)
Expand Down
2 changes: 1 addition & 1 deletion src/Marten/Exceptions/InvalidCompiledQueryException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Marten.Exceptions
{
public class InvalidCompiledQueryException: Exception
public class InvalidCompiledQueryException: MartenException
{
public static readonly string CompiledQueryTypeCannotBeAsyncMessage = "Invalid compiled query type `{0}`. Compiled queries cannot use asynchronous query selectors like 'CountAsync()'. Please use the synchronous equivalent like 'Count()' instead. You will still be able to query asynchronously through IQuerySession.QueryAsync().";

Expand Down
2 changes: 1 addition & 1 deletion src/Marten/Exceptions/InvalidDocumentException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Marten.Exceptions
[Serializable]
#endif

public class InvalidDocumentException: Exception
public class InvalidDocumentException: MartenException
{
public InvalidDocumentException(string message) : base(message)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Marten/Exceptions/InvalidProjectionException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Marten.Exceptions
/// <summary>
/// Thrown when any configuration rules for an active projection are violated and the projection is invalid
/// </summary>
public class InvalidProjectionException : Exception
public class InvalidProjectionException : MartenException
{
public InvalidProjectionException(string message) : base(message)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Marten/Exceptions/InvalidStreamOperationException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Marten.Exceptions
{
public class InvalidStreamOperationException: Exception
public class InvalidStreamOperationException: MartenException
{
public InvalidStreamOperationException(string message):
base(message)
Expand Down
2 changes: 1 addition & 1 deletion src/Marten/Exceptions/InvalidUtcDateTimeUsageException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#nullable enable
namespace Marten.Exceptions
{
public class InvalidUtcDateTimeUsageException : Exception
public class InvalidUtcDateTimeUsageException : MartenException
{
public InvalidUtcDateTimeUsageException(Exception inner) : base("DateTime with Kind=UTC is no longer supported by Npgsql. Consider switching to DateTimeOffset or NodaTime wherever possible, or see https://www.npgsql.org/efcore/release-notes/6.0.html.", inner)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Marten/Exceptions/MartenCommandException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Marten.Exceptions
/// <summary>
/// Wraps the Postgres command exceptions. Unifies exception handling and brings additonal information.
/// </summary>
public class MartenCommandException: Exception
public class MartenCommandException: MartenException
{
public const string MaybeLockedRowsMessage = "Postgresql timed out while trying to read data. This may be caused by trying to read locked rows";

Expand Down
27 changes: 27 additions & 0 deletions src/Marten/Exceptions/MartenException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Runtime.Serialization;

namespace Marten.Exceptions
{
/// <summary>
/// Base class for all Marten related exceptions
/// </summary>
public class MartenException : Exception
{
public MartenException()
{
}

protected MartenException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}

public MartenException(string message) : base(message)
{
}

public MartenException(string message, Exception innerException) : base(message, innerException)
{
}
}
}
2 changes: 1 addition & 1 deletion src/Marten/Exceptions/MartenSchemaException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Marten.Exceptions
[Serializable]
#endif

public class MartenSchemaException: Exception
public class MartenSchemaException: MartenException
{
public MartenSchemaException(object subject, string ddl, Exception inner) : base($"DDL Execution for '{subject}' Failed!\n\n{ddl}", inner)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Marten/Exceptions/NonExistentDocumentException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Marten.Exceptions
{
public class NonExistentDocumentException: Exception
public class NonExistentDocumentException: MartenException
{
public Type DocType { get; }
public object Id { get; }
Expand Down
2 changes: 1 addition & 1 deletion src/Marten/Exceptions/NonExistentStreamException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Marten.Exceptions
{
public class NonExistentStreamException: Exception
public class NonExistentStreamException: MartenException
{
public object Id { get; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Marten.Exceptions
{
public class ProgressionProgressOutOfOrderException : Exception
public class ProgressionProgressOutOfOrderException : MartenException
{
public ProgressionProgressOutOfOrderException(ShardName progressionOrShardName) : base($"Progression '{progressionOrShardName}' is out of order. This may happen when multiple processes try to process the projection")
{
Expand Down
2 changes: 1 addition & 1 deletion src/Marten/Exceptions/RollbackException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Marten.Exceptions
{
public class RollbackException: Exception
public class RollbackException: MartenException
{
public RollbackException(Exception innerException) : base("Failed while trying to rollback an exception", innerException)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Marten/Exceptions/StreamLockedException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Marten.Exceptions
{
public class StreamLockedException : Exception
public class StreamLockedException : MartenException
{
public StreamLockedException(object streamId, Exception innerException) : base($"Stream '{streamId}' may be locked for updates")
{
Expand Down
2 changes: 1 addition & 1 deletion src/Marten/Exceptions/UnknownEventTypeException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Marten.Exceptions
{
public class UnknownEventTypeException: Exception
public class UnknownEventTypeException: MartenException
{
public UnknownEventTypeException(string eventTypeName) : base((string)$"Unknown event type name alias '{eventTypeName}.' You may need to register this event type through StoreOptions.Events.AddEventType(type)")
{
Expand Down
3 changes: 2 additions & 1 deletion src/Marten/Storage/ITenancy.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Threading.Tasks;
using Marten.Exceptions;
using Marten.Schema;
using Weasel.Core.Migrations;

Expand Down Expand Up @@ -49,7 +50,7 @@ public interface ITenancy : IDatabaseSource

#endregion

public class UnknownTenantIdException: Exception
public class UnknownTenantIdException: MartenException
{
public UnknownTenantIdException(string tenantId) : base($"Unknown tenant id '{tenantId}'")
{
Expand Down

0 comments on commit d30755c

Please sign in to comment.