#!/usr/bin/env bash
# Pipe any log file through this to highlight the interrupt-worthy
# signals (from `temp/IOS_SIMULATOR_DEBUG_BUILD.md` §3.2.8 / "Reading
# the logs"). Strips known-noise lines.
#
# Usage:
#   scripts/dev/signal.sh temp/dev-logs/latest/ios-app-system.log
#   tail -F temp/dev-logs/latest/watch-app.log | scripts/dev/signal.sh -

set -euo pipefail

SIGNAL='javascript.*Error|RCTFatal|JSException|no active account|Maximum update|getSnapshot|RedBox|com.facebook.react.log:javascript.*\['
NOISE='Connection refused.*8097|instanceHandle is null|_TtC10RCTSwiftUI|imageio.*ftyp|BackBoard:EventDelivery aborting flush|Cannot connect to Expo CLI'

src="${1:-}"
if [[ -z "$src" || "$src" == "-" ]]; then
  grep -E --color=always --line-buffered "$SIGNAL" | grep -vE --line-buffered "$NOISE"
else
  grep -E --color=always "$SIGNAL" "$src" | grep -vE "$NOISE"
fi
