Skip to content

Commit

Permalink
Merge pull request #14 from MonacsLib/develop
Browse files Browse the repository at this point in the history
Monacs v.0.2.0
  • Loading branch information
bartsokol authored Mar 1, 2018
2 parents 0c7e6f2 + 6524c93 commit b613340
Show file tree
Hide file tree
Showing 17 changed files with 992 additions and 392 deletions.
257 changes: 234 additions & 23 deletions Monacs.Core/Async/Result.Async.Extensions.cs

Large diffs are not rendered by default.

29 changes: 27 additions & 2 deletions Monacs.Core/ErrorDetails.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,52 @@
using System;
using static Monacs.Core.Option;

namespace Monacs.Core
{
/// <summary>
/// Represents the details of the error in case of failed operation.
/// To create the instances use the factory methods from the <see cref="Errors"/> class.
/// </summary>
public struct ErrorDetails
{
public ErrorDetails(ErrorLevel level, Option<string> message, Option<string> key, Option<Exception> exception)
internal ErrorDetails(ErrorLevel level, Option<string> message, Option<string> key, Option<Exception> exception, Option<object> metadata)
{
Level = level;
Message = message;
Key = key;
Exception = exception;
Metadata = metadata;
}

/// <summary>
/// Contains the error severity described by <see cref="ErrorLevel"/>.
/// </summary>
public ErrorLevel Level { get; }

/// <summary>
/// Contains optional message to describe the error details.
/// </summary>
public Option<string> Message { get; }

/// <summary>
/// Contains optional error key to identify the error.
/// </summary>
public Option<string> Key { get; }

/// <summary>
/// Contains optional exception which operation ended up with.
/// Set to None if no exception occured.
/// </summary>
public Option<Exception> Exception { get; }

/// <summary>
/// Contains optional error metadata.
/// </summary>
public Option<object> Metadata { get; }
}

/// <summary>
/// Represents the severity of the error.
/// </summary>
public enum ErrorLevel
{
Trace = 0,
Expand Down
70 changes: 57 additions & 13 deletions Monacs.Core/Errors.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,70 @@
using System;
using static Monacs.Core.Option;

namespace Monacs.Core
{
/// <summary>
/// Contains factory methods to create instances of <see cref="ErrorDetails"/> in a more convenient way.
/// </summary>
public static class Errors
{
public static ErrorDetails Trace(string message = null, string key = null, Exception exception = null) =>
new ErrorDetails(ErrorLevel.Trace, message.ToOption(), key.ToOption(), exception.ToOption());
/// <summary>
/// Creates <see cref="ErrorDetails"/> with level <see cref="ErrorLevel.Trace"/>.
/// </summary>
/// <param name="message">Optional error message</param>
/// <param name="key">Optional key to identify the error</param>
/// <param name="exception">Optional exception which caused the error</param>
/// <param name="metadata">Optional error metadata</param>
public static ErrorDetails Trace(string message = null, string key = null, Exception exception = null, object metadata = null) =>
new ErrorDetails(ErrorLevel.Trace, message.ToOption(), key.ToOption(), exception.ToOption(), metadata.ToOption());

public static ErrorDetails Debug(string message = null, string key = null, Exception exception = null) =>
new ErrorDetails(ErrorLevel.Debug, message.ToOption(), key.ToOption(), exception.ToOption());
/// <summary>
/// Creates <see cref="ErrorDetails"/> with level <see cref="ErrorLevel.Debug"/>.
/// </summary>
/// <param name="message">Optional error message</param>
/// <param name="key">Optional key to identify the error</param>
/// <param name="exception">Optional exception which caused the error</param>
/// <param name="metadata">Optional error metadata</param>
public static ErrorDetails Debug(string message = null, string key = null, Exception exception = null, object metadata = null) =>
new ErrorDetails(ErrorLevel.Debug, message.ToOption(), key.ToOption(), exception.ToOption(), metadata.ToOption());

public static ErrorDetails Info(string message = null, string key = null, Exception exception = null) =>
new ErrorDetails(ErrorLevel.Info, message.ToOption(), key.ToOption(), exception.ToOption());
/// <summary>
/// Creates <see cref="ErrorDetails"/> with level <see cref="ErrorLevel.Info"/>.
/// </summary>
/// <param name="message">Optional error message</param>
/// <param name="key">Optional key to identify the error</param>
/// <param name="exception">Optional exception which caused the error</param>
/// <param name="metadata">Optional error metadata</param>
public static ErrorDetails Info(string message = null, string key = null, Exception exception = null, object metadata = null) =>
new ErrorDetails(ErrorLevel.Info, message.ToOption(), key.ToOption(), exception.ToOption(), metadata.ToOption());

public static ErrorDetails Warn(string message = null, string key = null, Exception exception = null) =>
new ErrorDetails(ErrorLevel.Warn, message.ToOption(), key.ToOption(), exception.ToOption());
/// <summary>
/// Creates <see cref="ErrorDetails"/> with level <see cref="ErrorLevel.Warn"/>.
/// </summary>
/// <param name="message">Optional error message</param>
/// <param name="key">Optional key to identify the error</param>
/// <param name="exception">Optional exception which caused the error</param>
/// <param name="metadata">Optional error metadata</param>
public static ErrorDetails Warn(string message = null, string key = null, Exception exception = null, object metadata = null) =>
new ErrorDetails(ErrorLevel.Warn, message.ToOption(), key.ToOption(), exception.ToOption(), metadata.ToOption());

public static ErrorDetails Error(string message = null, string key = null, Exception exception = null) =>
new ErrorDetails(ErrorLevel.Error, message.ToOption(), key.ToOption(), exception.ToOption());
/// <summary>
/// Creates <see cref="ErrorDetails"/> with level <see cref="ErrorLevel.Error"/>.
/// </summary>
/// <param name="message">Optional error message</param>
/// <param name="key">Optional key to identify the error</param>
/// <param name="exception">Optional exception which caused the error</param>
/// <param name="metadata">Optional error metadata</param>
public static ErrorDetails Error(string message = null, string key = null, Exception exception = null, object metadata = null) =>
new ErrorDetails(ErrorLevel.Error, message.ToOption(), key.ToOption(), exception.ToOption(), metadata.ToOption());

public static ErrorDetails Fatal(string message = null, string key = null, Exception exception = null) =>
new ErrorDetails(ErrorLevel.Fatal, message.ToOption(), key.ToOption(), exception.ToOption());
/// <summary>
/// Creates <see cref="ErrorDetails"/> with level <see cref="ErrorLevel.Fatal"/>.
/// </summary>
/// <param name="message">Optional error message</param>
/// <param name="key">Optional key to identify the error</param>
/// <param name="exception">Optional exception which caused the error</param>
/// <param name="metadata">Optional error metadata</param>
public static ErrorDetails Fatal(string message = null, string key = null, Exception exception = null, object metadata = null) =>
new ErrorDetails(ErrorLevel.Fatal, message.ToOption(), key.ToOption(), exception.ToOption(), metadata.ToOption());
}
}
1 change: 1 addition & 0 deletions Monacs.Core/Monacs.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<TargetFrameworks>netstandard1.3;net461</TargetFrameworks>
<NuspecFile>$(MSBuildThisFileDirectory)$(MSBuildProjectName).nuspec</NuspecFile>
<LangVersion>latest</LangVersion>
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
</PropertyGroup>

</Project>
2 changes: 1 addition & 1 deletion Monacs.Core/Monacs.Core.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
<id>Monacs.Core</id>
<version>0.1.0</version>
<version>0.2.0</version>
<authors>Bartosz Sokół</authors>
<owners>Bartosz Sokół</owners>
<licenseUrl>https://github.com/bartsokol/Monacs/blob/master/LICENSE</licenseUrl>
Expand Down
Loading

0 comments on commit b613340

Please sign in to comment.