Skip to content

fix: stop swallowing exceptions in import fire-and-forget pipeline runners#176

Open
davidortinau wants to merge 1 commit into
mainfrom
op-fix-import-catch-swallow
Open

fix: stop swallowing exceptions in import fire-and-forget pipeline runners#176
davidortinau wants to merge 1 commit into
mainfrom
op-fix-import-catch-swallow

Conversation

@davidortinau

Copy link
Copy Markdown
Owner

Problem

Three fire-and-forget Task.Run blocks in the import/channel endpoints had empty catch bodies with a misleading comment:

catch (Exception ex)
{
    // Logging happens inside the pipeline service
}

This comment is incorrect for exceptions thrown before the pipeline service's own try/catch (e.g. DI resolution failures, scope creation errors, the first pipeline step). When that happens:

  • ex is silently discarded
  • The import record is never updated to Failed
  • The caller polling /api/imports/{id} sees the import permanently stuck in Pending

Fix

Replace the empty catch with logging + status update in all three call sites:

catch (Exception ex)
{
    logger.LogError(ex, "Unhandled exception in import pipeline for import {ImportId}", import.Id);
    await pipelineService.FailImportAsync(import, ex.Message);
}

Changes

  • VideoImportPipelineService.cs — promoted FailImportAsync from private to public so endpoint handlers can call it
  • ImportEndpoints.csStartImport and RetryImport catch blocks now log the error and mark the import failed
  • ChannelEndpoints.cs — channel video trigger loop catch block gets the same fix

Verification

  • dotnet build src/SentenceStudio.Api/ — ✅ clean (0 errors)
  • dotnet test tests/SentenceStudio.Api.Tests/ — 120 pass; 19 failures are pre-existing on main (IChatClient not registered in auth test DI harness, unrelated to this change)

Replace empty catch blocks in StartImport, RetryImport (ImportEndpoints)
and TriggerCheck (ChannelEndpoints) with proper error handling:
- Log the exception via ILoggerFactory (Error level)
- Call FailImportAsync to mark the import as Failed with the error message

Make VideoImportPipelineService.FailImportAsync public so endpoints can
call it directly without needing a separate repository reference.

Previously, exceptions thrown before internal pipeline logging (DI
resolution failures, scope creation errors, first pipeline step) were
silently swallowed, leaving the import permanently stuck in Pending.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant