fix(worker-client): stop swallowing mutating hub call failures
TryInvokeAsync catches every exception and returns null, which is fine
for read-only calls but hid real HubException reasons behind a generic
"offline" message for the 7 mutating call sites (RestoreDefaultAgents,
UpsertPrimeSchedule, AddDailyNote, CleanupFinishedWorktrees,
ResetAllWorktrees, ForceRemoveWorktree, BuildPlanningIntegrationBranch)
— the same bug class fixed for ApproveReview in e1807fd. Each of the 22
TryInvokeAsync call sites was audited; the 15 read-only ones are left
unchanged (empty/offline is the right display). For the 7 switched to
a direct hub invoke, every caller was checked and, where it had no
catch, one was added so the exception surfaces (StatusMessage,
ShowErrorAsync/CombinedWarning) instead of crashing.
This commit is contained in:
@@ -19,6 +19,14 @@ public class PrimeClaudeTabViewModelTests
|
||||
public Task DeleteAsync(Guid id) { Deletes.Add(id); return Task.CompletedTask; }
|
||||
}
|
||||
|
||||
private sealed class ThrowingApi : IPrimeScheduleApi
|
||||
{
|
||||
public string ExceptionMessage { get; init; } = "worker offline";
|
||||
public Task<List<PrimeScheduleDto>> ListAsync() => Task.FromResult(new List<PrimeScheduleDto>());
|
||||
public Task<PrimeScheduleDto?> UpsertAsync(PrimeScheduleDto dto) => throw new Exception(ExceptionMessage);
|
||||
public Task DeleteAsync(Guid id) => Task.CompletedTask;
|
||||
}
|
||||
|
||||
private static PrimeScheduleDto Dto(Guid id, int days, TimeSpan time) =>
|
||||
new(id, days, time, true, null, null);
|
||||
|
||||
@@ -93,4 +101,19 @@ public class PrimeClaudeTabViewModelTests
|
||||
vm.AddScheduleCommand.Execute(null);
|
||||
Assert.Null(vm.Validate());
|
||||
}
|
||||
|
||||
// SettingsModalViewModel.Save() is the only place that catches Prime.SaveAsync's
|
||||
// failures (via a try/catch around the whole settings save) and surfaces them as
|
||||
// "Save failed: {message}". For that to work, SaveAsync must propagate the worker's
|
||||
// exception rather than swallow it.
|
||||
[Fact]
|
||||
public async Task Save_WhenApiThrows_PropagatesException()
|
||||
{
|
||||
var api = new ThrowingApi();
|
||||
var vm = new PrimeClaudeTabViewModel(api);
|
||||
vm.AddScheduleCommand.Execute(null);
|
||||
|
||||
var ex = await Assert.ThrowsAsync<Exception>(() => vm.SaveAsync());
|
||||
Assert.Equal(api.ExceptionMessage, ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user