-
-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Profile): Properly return issue when loading profile at applicati…
…on startup. Fixes SOUNDSWITCH-9T
- Loading branch information
Showing
4 changed files
with
68 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
namespace SoundSwitch.Framework.Profile; | ||
|
||
public record ProfileError(Profile Profile, string Error) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,53 @@ | ||
using System; | ||
using RailSharp.Internal.Result; | ||
|
||
#nullable enable | ||
|
||
namespace SoundSwitch.Util | ||
{ | ||
public static class ResultTypeExtension | ||
{ | ||
public static RailSharp.Result<TFailure, TSuccess> Catch<TFailure, TSuccess>( | ||
this RailSharp.Result<TFailure, TSuccess> result, | ||
Func<TFailure, RailSharp.Result<TFailure, TSuccess>> mapper) | ||
Func<TFailure, RailSharp.Result<TFailure, TSuccess>> mapper) | ||
{ | ||
return !(result is Failure<TFailure, TSuccess> failure) ? result : mapper((TFailure) failure); | ||
return !(result is Failure<TFailure, TSuccess> failure) ? result : mapper((TFailure)failure); | ||
} | ||
|
||
/// <summary> | ||
/// Unwrap the failure case | ||
/// </summary> | ||
/// <param name="result"></param> | ||
/// <param name="defaultValue"></param> | ||
/// <typeparam name="TFailure"></typeparam> | ||
/// <typeparam name="TSuccess"></typeparam> | ||
/// <returns></returns> | ||
public static TFailure? UnwrapFailure<TFailure, TSuccess>(this RailSharp.Result<TFailure, TSuccess> result, TFailure defaultValue = default) | ||
{ | ||
if (result is Failure<TFailure, TSuccess> failure) | ||
{ | ||
return failure; | ||
} | ||
|
||
return defaultValue; | ||
} | ||
|
||
/// <summary> | ||
/// Unwrap the success value | ||
/// </summary> | ||
/// <param name="result"></param> | ||
/// <param name="defaultValue"></param> | ||
/// <typeparam name="TFailure"></typeparam> | ||
/// <typeparam name="TSuccess"></typeparam> | ||
/// <returns></returns> | ||
public static TSuccess? UnwrapSuccess<TFailure, TSuccess>(this RailSharp.Result<TFailure, TSuccess> result, TSuccess? defaultValue = default) | ||
{ | ||
if (result is Success<TFailure, TSuccess> success) | ||
{ | ||
return success; | ||
} | ||
|
||
return defaultValue; | ||
} | ||
} | ||
} |