summaryrefslogtreecommitdiffstats
path: root/bin/json-assert-type
blob: 29cadad65817d492016d61a07273f6b44e7289f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#! /bin/sh
set -euf

formal_type=$1

actual_value=$2
actual_type=$(echo $actual_value | jq -r type)

if [ "$actual_type" != "$formal_type" ]; then
  backtrace
  printf 'error: expected %s, got %s\n' \
    "$formal_type" \
    "$actual_type" \
    >&2
  exit 1
fi

echo "$actual_value"