Skip to content

Commit

Permalink
chore: make contentTracing.stopRecording() failure clearer (#38520)
Browse files Browse the repository at this point in the history
chore: make contentTracing.stopRecording() failure clearer

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
  • Loading branch information
trop[bot] and codebytere committed May 31, 2023
1 parent 2281fbb commit 017fd30
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 9 additions & 4 deletions shell/browser/api/electron_api_content_tracing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,20 @@ void StopTracing(gin_helper::Promise<base::FilePath> 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)
Expand Down
2 changes: 1 addition & 1 deletion spec/api-content-tracing-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});

Expand Down

0 comments on commit 017fd30

Please sign in to comment.