| | | 1 | | namespace ZhEaIsNsAaBn.DbSeeder; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Thrown only by the EF seeding hook (<c>UseDbSeeder</c>): EF's <c>UseSeeding</c> callback can't return a result, and |
| | | 5 | | /// must fail <c>Migrate()</c>. Everywhere else DbSeeder returns <see cref="LayerResponse"/> errors. |
| | | 6 | | /// </summary> |
| | | 7 | | public sealed class DbSeederException : Exception |
| | | 8 | | { |
| | | 9 | | /// <summary>Creates the exception with no errors.</summary> |
| | 0 | 10 | | public DbSeederException() : this( "Seed migration failed." ) { } |
| | | 11 | | |
| | | 12 | | /// <summary>Creates the exception with a message and no errors.</summary> |
| | | 13 | | /// <param name="message">The message.</param> |
| | 0 | 14 | | public DbSeederException( string message ) : base( message ) => Errors = []; |
| | | 15 | | |
| | | 16 | | /// <summary>Creates the exception with a message, an inner exception and no errors.</summary> |
| | | 17 | | /// <param name="message">The message.</param> |
| | | 18 | | /// <param name="innerException">The cause.</param> |
| | 0 | 19 | | public DbSeederException( string message, Exception innerException ) : base( message, innerException ) => Errors = [ |
| | | 20 | | |
| | | 21 | | /// <summary>Creates the exception from the errors of a failed run.</summary> |
| | | 22 | | /// <param name="errors">The errors; the first one's exception becomes the inner exception.</param> |
| | | 23 | | public DbSeederException( IReadOnlyList<Error> errors ) |
| | 3 | 24 | | : base( $"Seed migration failed: {string.Join( ", ", ( errors ?? [] ).Select( e => e.Code ) )}.", errors?.FirstO |
| | 3 | 25 | | => Errors = errors ?? []; |
| | | 26 | | |
| | | 27 | | |
| | | 28 | | /// <summary>The errors of the failed run.</summary> |
| | | 29 | | public IReadOnlyList<Error> Errors { get; } |
| | | 30 | | } |