0
0
mirror of https://github.com/signalapp/libsignal.git synced 2024-09-20 03:52:17 +02:00
libsignal/swift/verify_error_codes.sh
Jordan Rose 53ba4c28c4 Swift: Add missing error cases
And set up a script to catch them in the future.
2024-04-04 12:57:26 -07:00

23 lines
844 B
Bash
Executable File

#!/bin/bash
#
# Copyright 2024 Signal Messenger, LLC.
# SPDX-License-Identifier: AGPL-3.0-only
#
set -euo pipefail
SCRIPT_DIR=$(dirname "$0")
cd "${SCRIPT_DIR}"/..
. bin/build_helpers.sh
# Get the list of *handled* error codes and the list of *declared* error codes and compare them.
# When modifying this script, be mindful of potential differences between GNU grep and BSD grep.
if ! diff -U 1 -L 'Codes handled in Error.swift' -L 'Codes declared in signal_ffi.h' \
<(grep -o -E 'case SignalErrorCode[^:]+' swift/Sources/LibSignalClient/Error.swift | cut -d' ' -f 2 | sort -u) \
<(grep -o -E '^ SignalErrorCode[^,]+' swift/Sources/SignalFfi/signal_ffi.h | grep -v 'UnknownError' | cut -d' ' -f 3 | sort -u)
then
printf '\n=== Make sure Error.swift is in sync with the error codes declared in Rust! ===\n\n' >&2
exit 1
fi