mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-05 09:33:25 -08:00
* [CrashReporting] Real send path with consent gating (DSN still placeholder)
require_user_consent + give/revoke around the Ask dialog, message event
with in-memory crash-log.txt bytes attachment, before_send scrubs
message/logentry/breadcrumbs/data of cockatrice:// secrets. Failure box
offers Save (shows path) / Discard (revokes + rejects) / Cancel (back
to dialog); reject() override so X/Escape cannot bypass revocation;
silent AlwaysSend path falls back to a local file. Empty DSN keeps the
previous mock behavior byte-identical.
Tests: 528/528 ctest green, format clean, code + UI gates PASS.
* [CrashReporting] Attach crash log and user note to the pending crash event
The redacted log used to ride a separate message event from the native
crash (minidump + stack), forcing manual correlation in Sentry. Fold it
into the pending crash envelope(s) instead by appending well-formed
attachment items before consent releases them: sentry-native replays
cached envelopes byte-for-byte (raw read, raw serialize in 0.17.3), so
the appended crash-log.txt and user-note.txt items upload with the very
event that already carries the dump and stack.
Covers both storage locations: Ask mode's consent-held files in
<database>/cache and AlwaysSend's transport-dumped files in
<database>/<run>.run, which must be attached before sentry_init replays
them. When no pending crash event exists (unclean exit without a native
crash) the standalone message event remains as fallback, now also
carrying the optional note.
The dialog gains an optional free-text field ('Here's what I was
doing...') that travels as user-note.txt; the mock JSON records it too.
* [CrashReporting] Send PROJECT_VERSION as the Sentry release
main() reported VERSION_STRING (PROJECT_VERSION_FRIENDLY) as the Sentry
release — that carries a build date, so every build of the same version
landed in its own release, and it never matched the installer, which
reports CPACK/PROJECT_VERSION. Bake COCKATRICE_SENTRY_RELEASE=
PROJECT_VERSION instead: date-free, identical between client and
installer, and derived from the git tag on tag builds, so events,
symbol uploads and the installer log all group under one release.
* [CrashReporting] Friendlier crash dialog copy
Reword the report dialog along a single friendly arc: headline ('Oops,
we crashed — and now we need your help to make Cockatrice better!'),
why helping is easy, exactly what gets collected (crash dump with stack
trace, app version, OS info, redacted log excerpt), the value of each
report ('better and less crashy for everyone'), and the consent choice
('Send and remember makes this automatic without interruption in the
future'). The checkbox itself stays direction-neutral ('Remember my
choice') because it also persists a 'Don't send' decision.
* [CrashReporting] Log where crash reports go and warn when they cannot
The client resolved COCKATRICE_SENTRY_DSN (environment over the baked-in
value) without ever saying which one won, and sentry-native refuses to build
a request for a DSN it considers invalid without reporting anything, so a
tester pointing the client at a scratch project had nothing to go on when a
crash never appeared.
Say which DSN source won, and log the destination (host and project id, never
the key) once the SDK is armed. Warn instead of staying quiet when no DSN is
configured at all, when a DSN is malformed - disabling reporting rather than
silently falling back to the project baked into the build, which is the rule
the installer already follows in cmake/CrashReporting.cmake - and when the
build was compiled without Sentry support. A deliberate Never-send stays at
info level: that is a choice, not a misconfiguration.
Also warn when a pending crash envelope was captured for a different
destination than the session that will upload it. sentry-native posts every
envelope with the DSN held in the transport state of the session doing the
sending, and envelopes restored from disk are raw, so the "dsn" header of a
cached envelope is never read: a crash captured for one project can be
uploaded to another with nothing in the log to show it.
Tests cover the DSN shape check (same unanchored pattern the build matches, so
a DSN this build accepted is never rejected here), destination description
without the key, and the mismatch detection, which stays quiet for a different
key on the same project, unreadable files, and headers without a dsn.
---------
Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
131 lines
5.9 KiB
CMake
131 lines
5.9 KiB
CMake
# Crash reporting via sentry-native (Sentry protocol, MIT).
|
|
# Included once from the root CMakeLists.txt, right after the sanitizer/coverage helpers.
|
|
#
|
|
# Inputs:
|
|
# WITH_CRASH_REPORTING -- build the client with the sentry-native SDK (default OFF, our release
|
|
# CI passes ON; packagers and from-source builds stay SDK-free until this
|
|
# ships something real, so offline package builds never fetch the SDK)
|
|
# COCKATRICE_SENTRY_DSN -- Sentry DSN baked into the build (default empty = SDK init skipped at runtime)
|
|
# COCKATRICE_SENTRY_TAG -- sentry-native release tag to vendor via FetchContent
|
|
# ENABLE_SANITIZERS -- forces the sentry backend to "none" (crashpad vs ASan conflict)
|
|
# Defines: cockatrice_target_enable_crash_reporting(<target>)
|
|
|
|
option(WITH_CRASH_REPORTING "Build with crash reporting via sentry-native" OFF)
|
|
set(COCKATRICE_SENTRY_DSN
|
|
""
|
|
CACHE STRING "Sentry DSN baked into the client; empty disables crash-report upload at runtime"
|
|
)
|
|
# Pinned stable release; tag verified at https://github.com/getsentry/sentry-native/tags.
|
|
set(COCKATRICE_SENTRY_TAG
|
|
"0.17.3"
|
|
CACHE STRING "sentry-native release tag to vendor via FetchContent"
|
|
)
|
|
|
|
# Wire the SDK (or the no-op fallback) into a client target. Always callable: with the
|
|
# option OFF the compile definitions below make crash_reporter.cpp compile to no-ops.
|
|
function(cockatrice_target_enable_crash_reporting _target)
|
|
if(WITH_CRASH_REPORTING AND TARGET sentry::sentry)
|
|
target_link_libraries(${_target} PRIVATE sentry::sentry)
|
|
target_compile_definitions(${_target} PRIVATE COCKATRICE_WITH_CRASH_REPORTING=1)
|
|
else()
|
|
target_compile_definitions(${_target} PRIVATE COCKATRICE_WITH_CRASH_REPORTING=0)
|
|
endif()
|
|
# Always baked in (possibly empty): main() prefers the COCKATRICE_SENTRY_DSN env var at runtime.
|
|
target_compile_definitions(${_target} PRIVATE "COCKATRICE_SENTRY_DSN=\"${COCKATRICE_SENTRY_DSN}\"")
|
|
# Sentry release for events from this target: PROJECT_VERSION (getversion.cmake ran before this
|
|
# file was included). Deliberately not PROJECT_VERSION_FRIENDLY / VERSION_STRING — that carries
|
|
# a build date, so every build of the same version would land in a different Sentry release.
|
|
# PROJECT_VERSION matches what the installer reports in its own log and what CPack derives the
|
|
# package version from, so client and installer events group under one release.
|
|
target_compile_definitions(${_target} PRIVATE "COCKATRICE_SENTRY_RELEASE=\"${PROJECT_VERSION}\"")
|
|
endfunction()
|
|
|
|
if(WITH_CRASH_REPORTING AND WITH_CLIENT)
|
|
include(FetchContent)
|
|
|
|
if(ENABLE_SANITIZERS)
|
|
# The crash handler cannot run under ASan/UBSan, so there is no backend to capture with.
|
|
set(_sentry_backend "none")
|
|
elseif(WIN32 OR APPLE)
|
|
# Out-of-process handler; shipping the handler binary is a later increment, which unifies
|
|
# every OS on breakpad (in-process, no extra binary to ship).
|
|
set(_sentry_backend "crashpad")
|
|
else()
|
|
# In-process, no extra binary to ship.
|
|
set(_sentry_backend "breakpad")
|
|
endif()
|
|
# FORCE so toggling ENABLE_SANITIZERS on a reused build dir cannot leave a stale backend behind.
|
|
set(SENTRY_BACKEND
|
|
"${_sentry_backend}"
|
|
CACHE STRING "Crash handler backend for sentry-native" FORCE
|
|
)
|
|
unset(_sentry_backend)
|
|
|
|
# No Qt integration: it runs find_package(Qt6) inside the vendored build, which
|
|
# cannot see our thin/aqt Qt layouts (macOS CI) under foreign toolchains, and its
|
|
# breadcrumbs could carry unredacted log lines into native crash events that bypass
|
|
# before_send. Our attached redacted log preview already carries the log context.
|
|
set(SENTRY_INTEGRATION_QT
|
|
OFF
|
|
CACHE BOOL "Qt log-message breadcrumbs for sentry-native (off: discovery + secret surface)" FORCE
|
|
)
|
|
# The transport stays at the SDK default (curl on Apple/Linux, winhttp on Windows).
|
|
set(SENTRY_BUILD_TESTS
|
|
OFF
|
|
CACHE BOOL "Build sentry-native tests" FORCE
|
|
)
|
|
set(SENTRY_BUILD_EXAMPLES
|
|
OFF
|
|
CACHE BOOL "Build sentry-native examples" FORCE
|
|
)
|
|
|
|
fetchcontent_declare(
|
|
sentry
|
|
GIT_REPOSITORY https://github.com/getsentry/sentry-native.git
|
|
GIT_TAG ${COCKATRICE_SENTRY_TAG}
|
|
GIT_SHALLOW TRUE
|
|
)
|
|
fetchcontent_makeavailable(sentry)
|
|
|
|
# Vendored sentry-native (and its breakpad/crashpad trees) warn under our -Wall -Wextra
|
|
# (e.g. breakpad's -Wmissing-field-initializers), and WARNING_AS_ERROR would fail the build
|
|
# on code we cannot fix. Those findings are not actionable for us, so opt the whole vendored
|
|
# tree out of warnings-as-errors while keeping the warnings themselves visible; our own
|
|
# targets keep -Werror. Interface libraries compile nothing, so they are skipped outright:
|
|
# an INTERFACE -Wno-error would propagate to our consumers and weaken their build.
|
|
function(_cockatrice_sentry_opt_out_of_werror _dir)
|
|
get_property(
|
|
_sentry_targets
|
|
DIRECTORY "${_dir}"
|
|
PROPERTY BUILDSYSTEM_TARGETS
|
|
)
|
|
foreach(_sentry_target IN LISTS _sentry_targets)
|
|
get_target_property(_sentry_type ${_sentry_target} TYPE)
|
|
if(_sentry_type STREQUAL "INTERFACE_LIBRARY")
|
|
continue()
|
|
elseif(_sentry_type MATCHES "LIBRARY|EXECUTABLE")
|
|
get_target_property(_sentry_imported ${_sentry_target} IMPORTED)
|
|
if(NOT _sentry_imported)
|
|
target_compile_options(${_sentry_target} PRIVATE -Wno-error)
|
|
endif()
|
|
endif()
|
|
endforeach()
|
|
get_property(
|
|
_sentry_subdirs
|
|
DIRECTORY "${_dir}"
|
|
PROPERTY SUBDIRECTORIES
|
|
)
|
|
foreach(_sentry_subdir IN LISTS _sentry_subdirs)
|
|
_cockatrice_sentry_opt_out_of_werror("${_sentry_subdir}")
|
|
endforeach()
|
|
endfunction()
|
|
if(NOT MSVC)
|
|
_cockatrice_sentry_opt_out_of_werror("${sentry_SOURCE_DIR}")
|
|
endif()
|
|
|
|
message(STATUS "Crash reporting: sentry-native ${COCKATRICE_SENTRY_TAG} (backend: ${SENTRY_BACKEND})")
|
|
else()
|
|
message(STATUS "Crash reporting: SDK not vendored "
|
|
"(WITH_CRASH_REPORTING=${WITH_CRASH_REPORTING}, WITH_CLIENT=${WITH_CLIENT})"
|
|
)
|
|
endif()
|