Skip to content

Fix jq parse error on parallel iOS commands (iscreenshot -a)#233

Open
vrbajiva wants to merge 1 commit into
masterfrom
fix/iscreenshot-parallel-jq-race
Open

Fix jq parse error on parallel iOS commands (iscreenshot -a)#233
vrbajiva wants to merge 1 commit into
masterfrom
fix/iscreenshot-parallel-jq-race

Conversation

@vrbajiva

Copy link
Copy Markdown
Collaborator

Problem

Running iscreenshot -a (or other parallel iOS commands) prints:

jq: parse error: Invalid numeric literal at line 2, column 30

Screenshots still save, but the error is printed for every-but-one device.

Cause

All iOS commands share a single temp file for go-ios output:

# common_tools
TEMPORARY_FILE="/private/tmp/mobile-toolkit-cache"

iscreenshot -a runs screenshot "$ID" & per device concurrently. Each calls ios_device_info, which does go-ios info > "$TEMPORARY_FILE" and immediately reads it back with jq. With multiple devices, one job overwrites the file while another is mid-read → garbled/partial JSON → the jq parse error. Single-device runs never hit it (no concurrency).

Fix

ios_device_info now uses a per-device temp file keyed by the (unique) UDID, so concurrent jobs never collide:

local TEMPORARY_FILE="$TEMPORARY_FILE-${1//[^A-Za-z0-9]/_}"
  • Callees (ios_check_pairing, ios_check_developer_image) inherit the value via bash dynamic scope, so the whole chain stays consistent.
  • The file is cleaned up (rm -f) afterwards.
  • Matches the existing per-invocation temp-file idiom already used in iinstall and irecord.

Testing

  • shellcheck (with the CI-disabled rules SC1090/SC2207/SC2001/SC1091) reports no new findings vs. before the change.
  • changelog.txt updated per CONTRIBUTING.

🤖 Generated with Claude Code

All iOS commands shared a single temp file (/private/tmp/mobile-toolkit-cache)
for go-ios output. When iscreenshot -a runs device-info gathering concurrently
per device, one job overwrote the file while another was reading it with jq,
yielding garbled JSON and "jq: parse error: Invalid numeric literal".

ios_device_info now uses a per-device temp file keyed by the (unique) UDID, so
concurrent jobs never collide. Callees (ios_check_pairing,
ios_check_developer_image) inherit the value via bash dynamic scope, and the
file is cleaned up afterwards. Matches the existing per-invocation temp-file
idiom already used in iinstall and irecord.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@vrbajiva
vrbajiva requested a review from IGPenguin July 23, 2026 08:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant