From 1ada50de86373480b218c6bf6f372eb0a02d436b Mon Sep 17 00:00:00 2001 From: Devis Lucato Date: Mon, 18 Nov 2024 12:36:04 -0800 Subject: [PATCH] Stop retrying unsupported file types --- .../Pipeline/MimeTypeException.cs | 26 +++++++++++++++++++ service/Abstractions/Pipeline/MimeTypes.cs | 2 +- service/Core/Pipeline/BaseOrchestrator.cs | 2 +- 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 service/Abstractions/Pipeline/MimeTypeException.cs diff --git a/service/Abstractions/Pipeline/MimeTypeException.cs b/service/Abstractions/Pipeline/MimeTypeException.cs new file mode 100644 index 000000000..3a305790d --- /dev/null +++ b/service/Abstractions/Pipeline/MimeTypeException.cs @@ -0,0 +1,26 @@ +// Copyright (c) Microsoft. All rights reserved. + +using System; + +namespace Microsoft.KernelMemory.Pipeline; + +public class MimeTypeException : KernelMemoryException +{ + /// + public MimeTypeException(bool? isTransient = null) + { + this.IsTransient = isTransient; + } + + /// + public MimeTypeException(string message, bool? isTransient = null) : base(message) + { + this.IsTransient = isTransient; + } + + /// + public MimeTypeException(string message, Exception? innerException, bool? isTransient = null) : base(message, innerException) + { + this.IsTransient = isTransient; + } +} diff --git a/service/Abstractions/Pipeline/MimeTypes.cs b/service/Abstractions/Pipeline/MimeTypes.cs index 6efdc4aa8..956eeae39 100644 --- a/service/Abstractions/Pipeline/MimeTypes.cs +++ b/service/Abstractions/Pipeline/MimeTypes.cs @@ -221,7 +221,7 @@ public string GetFileType(string filename) return mimeType; } - throw new NotSupportedException($"File type not supported: {filename}"); + throw new MimeTypeException($"File type not supported: {filename}", isTransient: false); } public bool TryGetFileType(string filename, out string? mimeType) diff --git a/service/Core/Pipeline/BaseOrchestrator.cs b/service/Core/Pipeline/BaseOrchestrator.cs index 8311c0406..c613139b6 100644 --- a/service/Core/Pipeline/BaseOrchestrator.cs +++ b/service/Core/Pipeline/BaseOrchestrator.cs @@ -477,7 +477,7 @@ private async Task UploadFormFilesAsync(DataPipeline pipeline, CancellationToken { mimeType = this._mimeTypeDetection.GetFileType(file.FileName); } - catch (NotSupportedException) + catch (MimeTypeException) { this.Log.LogWarning("File type not supported, the ingestion pipeline might skip it"); }