Skip to content

Commit

Permalink
Improve validation failure reporting
Browse files Browse the repository at this point in the history
Consolidated validation exception
Refactoring
  • Loading branch information
nullpainter committed Oct 5, 2020
1 parent aba141d commit ae59a95
Show file tree
Hide file tree
Showing 47 changed files with 119 additions and 97 deletions.
13 changes: 11 additions & 2 deletions Sanchez.Processing/Extensions/Images/ImageExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System.IO;
using System;
using System.IO;
using System.Reflection;
using System.Threading.Tasks;
using ExifLibrary;
using FluentValidation;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;

Expand All @@ -22,7 +24,14 @@ public static async Task SaveWithExifAsync(this Image<Rgba32> image, string path
}

// Save image
await image.SaveAsync(path);
try
{
await image.SaveAsync(path);
}
catch (NotSupportedException)
{
throw new ValidationException($"Unsupported output file extension: {Path.GetExtension(path)}");
}

// Add EXIF metadata to image
var version = Assembly.GetExecutingAssembly().GetName().Version;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CREATE TABLE UnderlayCache(
CREATE TABLE IF NOT EXISTS UnderlayCache(
Id INTEGER PRIMARY KEY AUTOINCREMENT,
Filename TEXT NOT NULL,
Longitude NUMERIC,
Expand Down
7 changes: 5 additions & 2 deletions Sanchez.Processing/Services/FileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public interface IFileService
/// can be a single file, a directory or a glob and wildcard pattern (such as <c>source/**/*IR.jpg</c>)
/// </summary>
List<string> GetSourceFiles();

List<Registration> ToRegistrations(List<string> sourceFiles);

/// <summary>
Expand Down Expand Up @@ -76,7 +76,10 @@ public List<string> GetSourceFiles()
var absolutePath = Path.GetFullPath(_options.SourcePath!);

// Source is a single file
if (!_options.MultipleSources) return new List<string> { absolutePath };
if (!_options.MultipleSources)
{
return File.Exists(absolutePath) ? new List<string> { absolutePath } : new List<string>();
}

// If the source is a directory, enumerate all files
if (Directory.Exists(absolutePath))
Expand Down
27 changes: 0 additions & 27 deletions Sanchez.Shared/Exceptions/ValidationException.cs

This file was deleted.

3 changes: 1 addition & 2 deletions Sanchez.Workflow/Extensions/StepExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Sanchez.Workflow.Models;
using Sanchez.Workflow.Models.Data;
using Sanchez.Workflow.Models.Data;
using Sanchez.Workflow.Steps.Common;
using WorkflowCore.Interface;

Expand Down
3 changes: 1 addition & 2 deletions Sanchez.Workflow/Extensions/WorkflowExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Sanchez.Workflow.Models;
using Sanchez.Workflow.Models.Data;
using Sanchez.Workflow.Models.Data;
using Sanchez.Workflow.Models.Steps;
using WorkflowCore.Interface;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using JetBrains.Annotations;
using Sanchez.Workflow.Workflows.Equirectangular;
using SixLabors.ImageSharp;

namespace Sanchez.Workflow.Models.Data
{
/// <summary>
/// Data backing <see cref="EquirectangularStitchWorkflow"/>.
/// Data backing <see cref="Sanchez.Workflow.Workflows.Equirectangular.EquirectangularStitchWorkflow"/>.
/// </summary>
public class EquirectangularStitchWorkflowData : WorkflowData
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using System;
using System.Collections.Generic;
using JetBrains.Annotations;
using Sanchez.Workflow.Workflows.Equirectangular;
using ShellProgressBar;

namespace Sanchez.Workflow.Models.Data
{
/// <summary>
/// Data backing <see cref="EquirectangularTimelapseWorkflow"/>.
/// Data backing <see cref="Sanchez.Workflow.Workflows.Equirectangular.EquirectangularTimelapseWorkflow"/>.
/// </summary>
public class EquirectangularTimelapseWorkflowData : EquirectangularStitchWorkflowData
{
Expand Down
7 changes: 2 additions & 5 deletions Sanchez.Workflow/Models/Data/GeostationaryWorkflowData.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@

using Sanchez.Workflow.Workflows.Geostationary;

namespace Sanchez.Workflow.Models.Data
namespace Sanchez.Workflow.Models.Data
{
/// <summary>
/// Data backing <see cref="GeostationaryWorkflow"/>.
/// Data backing <see cref=" Sanchez.Workflow.Workflows.Geostationary.GeostationaryWorkflow"/>.
/// </summary>
public class GeostationaryWorkflowData : WorkflowData
{
Expand Down
4 changes: 2 additions & 2 deletions Sanchez.Workflow/Models/Data/WorkflowData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public interface IWorkflowData
/// </summary>
/// <remarks>
/// This is arguably a misuse of WorkflowCore data, as it should be able to be serialized. Add disposable
/// services and binary data breaks this pattern.
/// services and binary data breaks this pattern. In practice, this state needs to be available somewhere,
/// and the workflows aren't log enough to warrant having a persistence provider specified.
/// </remarks>
// TODO check if WorkflowCore has some sort of never serialize flag
public abstract class WorkflowData : IWorkflowData, IDisposable
{
/// <summary>
Expand Down
8 changes: 5 additions & 3 deletions Sanchez.Workflow/Services/WorkflowService.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using FluentValidation;
using Sanchez.Processing.Models;
using Sanchez.Shared.Exceptions;
using Sanchez.Workflow.Models;
using Sanchez.Workflow.Models.Data;
using Sanchez.Workflow.Workflows.Equirectangular;
Expand Down Expand Up @@ -31,7 +31,7 @@ public sealed class WorkflowService : IWorkflowService, IDisposable

private readonly AutoResetEvent _resetEvent;
private string? _workflowId;
private bool _initialised = false;
private bool _initialised;

public WorkflowService(
RenderOptions options,
Expand Down Expand Up @@ -110,11 +110,13 @@ private void OnLifeCycleEvent(CancellationTokenSource cancellationToken, LifeCyc

private void OnStepError(Exception exception, WorkflowInstance workflow)
{
DisposeData();

switch (exception)
{
case ValidationException validationException:
Console.WriteLine(validationException.Message);
Log.Error(validationException.Message);
Log.Warning(validationException.Message);
break;
default:
if (!_options.Verbose) Console.WriteLine("Unhandled failure; check logs for details, or run again with verbose logging (-v / --verbose)");
Expand Down
1 change: 0 additions & 1 deletion Sanchez.Workflow/Steps/Common/ColourCorrect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using JetBrains.Annotations;
using Sanchez.Processing.Models;
using Sanchez.Workflow.Extensions;
using Sanchez.Workflow.Models;
using Sanchez.Workflow.Models.Data;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
Expand Down
1 change: 0 additions & 1 deletion Sanchez.Workflow/Steps/Common/CreateActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Sanchez.Processing.Models.Projections;
using Sanchez.Processing.Services;
using Sanchez.Workflow.Extensions;
using Sanchez.Workflow.Models;
using Sanchez.Workflow.Models.Data;
using WorkflowCore.Interface;
using WorkflowCore.Models;
Expand Down
10 changes: 6 additions & 4 deletions Sanchez.Workflow/Steps/Common/GetSourceFiles.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using FluentValidation;
using Sanchez.Processing.Models.Projections;
using Sanchez.Processing.Services;
using Sanchez.Shared.Exceptions;
using Sanchez.Workflow.Extensions;
using Sanchez.Workflow.Models;
using Sanchez.Workflow.Models.Data;
using WorkflowCore.Interface;
using WorkflowCore.Models;
Expand All @@ -23,11 +23,13 @@ public override ExecutionResult Run(IStepExecutionContext context)
try
{
var sourceFiles = _fileService.GetSourceFiles();
if (!sourceFiles.Any()) throw new ValidationException("No source files found");

SourceRegistrations = _fileService.ToRegistrations(sourceFiles);
}
catch (DirectoryNotFoundException e)
catch (DirectoryNotFoundException)
{
throw new ValidationException("Source directory not found", e);
throw new ValidationException("Source directory not found");
}

return ExecutionResult.Next();
Expand Down
1 change: 0 additions & 1 deletion Sanchez.Workflow/Steps/Common/InitialiseProgressBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Sanchez.Processing.Helpers;
using Sanchez.Processing.Models;
using Sanchez.Workflow.Extensions;
using Sanchez.Workflow.Models;
using Sanchez.Workflow.Models.Data;
using ShellProgressBar;
using WorkflowCore.Interface;
Expand Down
3 changes: 1 addition & 2 deletions Sanchez.Workflow/Steps/Common/InitialiseSatelliteRegistry.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using System;
using System.Threading.Tasks;
using FluentValidation;
using Microsoft.Extensions.Logging;
using Sanchez.Processing.Services;
using Sanchez.Shared.Exceptions;
using Sanchez.Workflow.Extensions;
using Sanchez.Workflow.Models;
using Sanchez.Workflow.Models.Data;
using WorkflowCore.Interface;
using WorkflowCore.Models;
Expand Down
1 change: 0 additions & 1 deletion Sanchez.Workflow/Steps/Common/InitialiseUnderlayCache.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Sanchez.Processing.Services.Underlay;
using Sanchez.Workflow.Extensions;
using Sanchez.Workflow.Models;
using Sanchez.Workflow.Models.Data;
using WorkflowCore.Interface;
using WorkflowCore.Models;
Expand Down
1 change: 0 additions & 1 deletion Sanchez.Workflow/Steps/Common/LoadImageSingle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Ardalis.GuardClauses;
using Sanchez.Processing.Models.Projections;
using Sanchez.Workflow.Extensions;
using Sanchez.Workflow.Models;
using Sanchez.Workflow.Models.Data;
using Sanchez.Workflow.Models.Steps;
using WorkflowCore.Interface;
Expand Down
1 change: 0 additions & 1 deletion Sanchez.Workflow/Steps/Common/LogCompletion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using JetBrains.Annotations;
using Microsoft.Extensions.Logging;
using Sanchez.Workflow.Extensions;
using Sanchez.Workflow.Models;
using Sanchez.Workflow.Models.Data;
using Sanchez.Workflow.Models.Steps;
using ShellProgressBar;
Expand Down
1 change: 0 additions & 1 deletion Sanchez.Workflow/Steps/Common/NormaliseImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using Sanchez.Processing.Models;
using Sanchez.Processing.Models.Projections;
using Sanchez.Workflow.Extensions;
using Sanchez.Workflow.Models;
using Sanchez.Workflow.Models.Data;
using Sanchez.Workflow.Models.Steps;
using WorkflowCore.Interface;
Expand Down
1 change: 0 additions & 1 deletion Sanchez.Workflow/Steps/Common/SaveImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Sanchez.Processing.Extensions.Images;
using Sanchez.Processing.Models.Projections;
using Sanchez.Workflow.Extensions;
using Sanchez.Workflow.Models;
using Sanchez.Workflow.Models.Data;
using Sanchez.Workflow.Models.Steps;
using SixLabors.ImageSharp;
Expand Down
1 change: 0 additions & 1 deletion Sanchez.Workflow/Steps/Common/SetWorkflowRegistration.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Sanchez.Processing.Models.Projections;
using Sanchez.Workflow.Extensions;
using Sanchez.Workflow.Models;
using Sanchez.Workflow.Models.Data;
using WorkflowCore.Interface;
using WorkflowCore.Models;
Expand Down
1 change: 0 additions & 1 deletion Sanchez.Workflow/Steps/Common/ShouldWriteSingle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Sanchez.Processing.Models.Projections;
using Sanchez.Processing.Services;
using Sanchez.Workflow.Extensions;
using Sanchez.Workflow.Models;
using Sanchez.Workflow.Models.Data;
using Sanchez.Workflow.Models.Steps;
using ShellProgressBar;
Expand Down
1 change: 0 additions & 1 deletion Sanchez.Workflow/Steps/Equirectangular/RegisterImages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Sanchez.Processing.Models.Projections;
using Sanchez.Processing.Services;
using Sanchez.Workflow.Extensions;
using Sanchez.Workflow.Models;
using Sanchez.Workflow.Models.Data;
using WorkflowCore.Interface;
using WorkflowCore.Models;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Sanchez.Processing.Models;
using Sanchez.Workflow.Extensions;
using Sanchez.Workflow.Models;
using Sanchez.Workflow.Models.Data;
using WorkflowCore.Interface;
using WorkflowCore.Models;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Ardalis.GuardClauses;
using Sanchez.Processing.Models;
using Sanchez.Workflow.Extensions;
using Sanchez.Workflow.Models;
using Sanchez.Workflow.Models.Data;
using Sanchez.Workflow.Models.Steps;
using WorkflowCore.Interface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using Sanchez.Processing.Models;
using Sanchez.Processing.Services;
using Sanchez.Workflow.Extensions;
using Sanchez.Workflow.Models;
using Sanchez.Workflow.Models.Data;
using Sanchez.Workflow.Models.Steps;
using WorkflowCore.Interface;
Expand Down
1 change: 0 additions & 1 deletion Sanchez.Workflow/Steps/Equirectangular/Stitch/CropImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using Sanchez.Processing.Extensions;
using Sanchez.Processing.Models;
using Sanchez.Workflow.Extensions;
using Sanchez.Workflow.Models;
using Sanchez.Workflow.Models.Data;
using Sanchez.Workflow.Models.Steps;
using SixLabors.ImageSharp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Sanchez.Processing.Models;
using Sanchez.Processing.Models.Projections;
using Sanchez.Workflow.Extensions;
using Sanchez.Workflow.Models;
using Sanchez.Workflow.Models.Data;
using Sanchez.Workflow.Models.Steps;
using SixLabors.ImageSharp;
Expand Down
1 change: 0 additions & 1 deletion Sanchez.Workflow/Steps/Equirectangular/Stitch/LoadImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Ardalis.GuardClauses;
using Sanchez.Processing.Models.Projections;
using Sanchez.Workflow.Extensions;
using Sanchez.Workflow.Models;
using Sanchez.Workflow.Models.Data;
using Sanchez.Workflow.Models.Steps;
using ShellProgressBar;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using Sanchez.Processing.Models;
using Sanchez.Processing.Services.Underlay;
using Sanchez.Workflow.Extensions;
using Sanchez.Workflow.Models;
using Sanchez.Workflow.Models.Data;
using Sanchez.Workflow.Models.Steps;
using SixLabors.ImageSharp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Sanchez.Processing.Models;
using Sanchez.Processing.Models.Projections;
using Sanchez.Workflow.Extensions;
using Sanchez.Workflow.Models;
using Sanchez.Workflow.Models.Data;
using Sanchez.Workflow.Models.Steps;
using ShellProgressBar;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Sanchez.Processing.Models;
using Sanchez.Processing.Services;
using Sanchez.Workflow.Extensions;
using Sanchez.Workflow.Models;
using Sanchez.Workflow.Models.Data;
using Sanchez.Workflow.Models.Steps;
using ShellProgressBar;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Sanchez.Processing.Models;
using Sanchez.Processing.Models.Projections;
using Sanchez.Workflow.Extensions;
using Sanchez.Workflow.Models;
using Sanchez.Workflow.Models.Data;
using Sanchez.Workflow.Models.Steps;
using SixLabors.ImageSharp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Sanchez.Processing.Models.Angles;
using Sanchez.Processing.Models.Projections;
using Sanchez.Workflow.Extensions;
using Sanchez.Workflow.Models;
using Sanchez.Workflow.Models.Data;
using Sanchez.Workflow.Models.Steps;
using SixLabors.ImageSharp;
Expand Down
Loading

0 comments on commit ae59a95

Please sign in to comment.