Skip to content

Commit 2daf568

Browse files
antonisclaude
andcommitted
refactor(ios): Extract dSYM check into helper to flatten nested ifs
Replace the 6-level nested if pyramid in wait_for_dsym_files() with a _sentry_check_dsym_ready() helper that uses guard clauses (early return). Also fixes the local var=$(subshell) anti-pattern where `local` always returns 0 and would mask subshell failures under `set -e`. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent a0fb53a commit 2daf568

1 file changed

Lines changed: 69 additions & 65 deletions

File tree

packages/core/scripts/sentry-xcode-debug-files.sh

Lines changed: 69 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,73 @@ EXTRA_ARGS="$SENTRY_CLI_EXTRA_ARGS $SENTRY_CLI_DEBUG_FILES_UPLOAD_EXTRA_ARGS $IN
5858

5959
UPLOAD_DEBUG_FILES="\"$SENTRY_CLI_EXECUTABLE\" debug-files upload $EXTRA_ARGS \"$DWARF_DSYM_FOLDER_PATH\""
6060

61+
# Check if dSYM files are fully generated and ready to upload.
62+
# Returns 0 (ready) or 1 (not ready yet), printing a status message in either case.
63+
_sentry_check_dsym_ready() {
64+
local dsym_folder="$1"
65+
local dsym_file_name="$2"
66+
local attempt="$3"
67+
local max_attempts="$4"
68+
69+
if [ ! -d "$dsym_folder" ]; then
70+
echo "dSYM folder does not exist yet: $dsym_folder (attempt $attempt/$max_attempts)"
71+
return 1
72+
fi
73+
74+
local dsym_count
75+
dsym_count=$(find "$dsym_folder" -name "*.dSYM" -type d 2>/dev/null | wc -l | tr -d ' ')
76+
if [ "$dsym_count" -eq 0 ]; then
77+
echo "No dSYM bundles found yet in $dsym_folder (attempt $attempt/$max_attempts)"
78+
return 1
79+
fi
80+
81+
echo "Found $dsym_count dSYM bundle(s) in $dsym_folder"
82+
83+
# DWARF_DSYM_FILE_NAME not set: check if any dSYM has valid DWARF content
84+
if [ -z "$dsym_file_name" ]; then
85+
for dsym in "$dsym_folder"/*.dSYM; do
86+
local dwarf_file
87+
dwarf_file=$(find "$dsym/Contents/Resources/DWARF" -type f -size +0 2>/dev/null | head -1)
88+
if [ -n "$dwarf_file" ]; then
89+
echo "Found dSYM bundle(s) with valid DWARF content"
90+
return 0
91+
fi
92+
done
93+
echo "Found dSYM bundle(s) but none have complete DWARF content yet (attempt $attempt/$max_attempts)"
94+
return 1
95+
fi
96+
97+
# DWARF_DSYM_FILE_NAME set: verify the main app dSYM is complete
98+
local main_dsym="$dsym_folder/$dsym_file_name"
99+
if [ ! -d "$main_dsym" ]; then
100+
echo "Main app dSYM not found yet: $dsym_file_name (attempt $attempt/$max_attempts)"
101+
return 1
102+
fi
103+
104+
local dwarf_dir="$main_dsym/Contents/Resources/DWARF"
105+
if [ ! -d "$dwarf_dir" ]; then
106+
echo "Main app dSYM structure incomplete (missing DWARF directory): $dsym_file_name (attempt $attempt/$max_attempts)"
107+
return 1
108+
fi
109+
110+
local dwarf_files
111+
dwarf_files=$(find "$dwarf_dir" -type f 2>/dev/null | head -1)
112+
if [ -z "$dwarf_files" ]; then
113+
echo "Main app dSYM DWARF directory is empty: $dsym_file_name (attempt $attempt/$max_attempts)"
114+
return 1
115+
fi
116+
117+
local dwarf_size
118+
dwarf_size=$(find "$dwarf_dir" -type f -size +0 2>/dev/null | head -1)
119+
if [ -z "$dwarf_size" ]; then
120+
echo "Main app dSYM DWARF binary is empty (still being written): $dsym_file_name (attempt $attempt/$max_attempts)"
121+
return 1
122+
fi
123+
124+
echo "Verified main app dSYM is complete: $dsym_file_name"
125+
return 0
126+
}
127+
61128
# Function to wait for dSYM files to be generated
62129
# This addresses a race condition where the upload script runs before dSYM generation completes
63130
wait_for_dsym_files() {
@@ -94,71 +161,8 @@ wait_for_dsym_files() {
94161
fi
95162

96163
while [ $attempt -le $max_attempts ]; do
97-
# Check if the dSYM folder exists
98-
if [ -d "$DWARF_DSYM_FOLDER_PATH" ]; then
99-
# Check if there are any .dSYM bundles in the folder
100-
local dsym_count=$(find "$DWARF_DSYM_FOLDER_PATH" -name "*.dSYM" -type d 2>/dev/null | wc -l | tr -d ' ')
101-
102-
if [ "$dsym_count" -gt 0 ]; then
103-
echo "Found $dsym_count dSYM bundle(s) in $DWARF_DSYM_FOLDER_PATH"
104-
105-
# If DWARF_DSYM_FILE_NAME is set, verify the main app dSYM exists and is complete
106-
if [ -n "$DWARF_DSYM_FILE_NAME" ]; then
107-
local main_dsym="$DWARF_DSYM_FOLDER_PATH/$DWARF_DSYM_FILE_NAME"
108-
109-
if [ -d "$main_dsym" ]; then
110-
# Directory exists, now verify the actual DWARF binary exists inside
111-
local dwarf_dir="$main_dsym/Contents/Resources/DWARF"
112-
113-
if [ -d "$dwarf_dir" ]; then
114-
# Check if there are any files in the DWARF directory
115-
local dwarf_files=$(find "$dwarf_dir" -type f 2>/dev/null | head -1)
116-
117-
if [ -n "$dwarf_files" ]; then
118-
# Verify the DWARF file is not empty (still being written)
119-
local dwarf_size=$(find "$dwarf_dir" -type f -size +0 2>/dev/null | head -1)
120-
121-
if [ -n "$dwarf_size" ]; then
122-
echo "Verified main app dSYM is complete: $DWARF_DSYM_FILE_NAME"
123-
return 0
124-
else
125-
echo "Main app dSYM DWARF binary is empty (still being written): $DWARF_DSYM_FILE_NAME (attempt $attempt/$max_attempts)"
126-
fi
127-
else
128-
echo "Main app dSYM DWARF directory is empty: $DWARF_DSYM_FILE_NAME (attempt $attempt/$max_attempts)"
129-
fi
130-
else
131-
echo "Main app dSYM structure incomplete (missing DWARF directory): $DWARF_DSYM_FILE_NAME (attempt $attempt/$max_attempts)"
132-
fi
133-
else
134-
echo "Main app dSYM not found yet: $DWARF_DSYM_FILE_NAME (attempt $attempt/$max_attempts)"
135-
fi
136-
else
137-
# DWARF_DSYM_FILE_NAME not set, check if any dSYM has valid DWARF content
138-
# This is less strict but better than nothing
139-
local has_valid_dsym=false
140-
for dsym in "$DWARF_DSYM_FOLDER_PATH"/*.dSYM; do
141-
if [ -d "$dsym/Contents/Resources/DWARF" ]; then
142-
local dwarf_files=$(find "$dsym/Contents/Resources/DWARF" -type f -size +0 2>/dev/null | head -1)
143-
if [ -n "$dwarf_files" ]; then
144-
has_valid_dsym=true
145-
break
146-
fi
147-
fi
148-
done
149-
150-
if [ "$has_valid_dsym" = true ]; then
151-
echo "Found dSYM bundle(s) with valid DWARF content"
152-
return 0
153-
else
154-
echo "Found dSYM bundle(s) but none have complete DWARF content yet (attempt $attempt/$max_attempts)"
155-
fi
156-
fi
157-
else
158-
echo "No dSYM bundles found yet in $DWARF_DSYM_FOLDER_PATH (attempt $attempt/$max_attempts)"
159-
fi
160-
else
161-
echo "dSYM folder does not exist yet: $DWARF_DSYM_FOLDER_PATH (attempt $attempt/$max_attempts)"
164+
if _sentry_check_dsym_ready "$DWARF_DSYM_FOLDER_PATH" "$DWARF_DSYM_FILE_NAME" "$attempt" "$max_attempts"; then
165+
return 0
162166
fi
163167

164168
if [ $attempt -lt $max_attempts ]; then

0 commit comments

Comments
 (0)