From 9e3fdd22036fee55208d3db24f6016198dcb76f2 Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Wed, 31 May 2023 13:55:03 +0000 Subject: [PATCH] chore: make contentTracing.stopRecording() failure clearer Co-authored-by: Shelley Vohr --- shell/browser/api/electron_api_content_tracing.cc | 13 +++++++++---- spec/api-content-tracing-spec.ts | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/shell/browser/api/electron_api_content_tracing.cc b/shell/browser/api/electron_api_content_tracing.cc index a1628bb7f37fa..120f53d7aec5b 100644 --- a/shell/browser/api/electron_api_content_tracing.cc +++ b/shell/browser/api/electron_api_content_tracing.cc @@ -78,15 +78,20 @@ void StopTracing(gin_helper::Promise promise, } }, std::move(promise), *file_path); - if (file_path) { + + auto* instance = TracingController::GetInstance(); + if (!instance->IsTracing()) { + std::move(resolve_or_reject) + .Run(absl::make_optional( + "Failed to stop tracing - no trace in progress")); + } else if (file_path) { auto split_callback = base::SplitOnceCallback(std::move(resolve_or_reject)); auto endpoint = TracingController::CreateFileEndpoint( *file_path, base::BindOnce(std::move(split_callback.first), absl::nullopt)); - if (!TracingController::GetInstance()->StopTracing(endpoint)) { + if (!instance->StopTracing(endpoint)) { std::move(split_callback.second) - .Run(absl::make_optional( - "Failed to stop tracing (was a trace in progress?)")); + .Run(absl::make_optional("Failed to stop tracing")); } } else { std::move(resolve_or_reject) diff --git a/spec/api-content-tracing-spec.ts b/spec/api-content-tracing-spec.ts index 7f36fc18da9f5..15cb26741e725 100644 --- a/spec/api-content-tracing-spec.ts +++ b/spec/api-content-tracing-spec.ts @@ -113,7 +113,7 @@ ifdescribe(!(['arm', 'arm64', 'ia32'].includes(process.arch)))('contentTracing', }); it('rejects if no trace is happening', async () => { - await expect(contentTracing.stopRecording()).to.be.rejected(); + await expect(contentTracing.stopRecording()).to.be.rejectedWith('Failed to stop tracing - no trace in progress'); }); });