improve error handling

This commit is contained in:
felixlohmeier 2022-11-13 22:14:01 +00:00
parent be57685be2
commit b156066112
3 changed files with 17 additions and 3 deletions

View File

@ -76,7 +76,7 @@ Optional:
3. Remove duplicates by applying an undo/redo JSON file 3. Remove duplicates by applying an undo/redo JSON file
```sh ```sh
orcli transform "duplicates" "https://git.io/fj5hF" orcli transform "duplicates" "https://git.io/fj5ju"
``` ```
4. Export data from OpenRefine project to tab-separated-values (TSV) file `duplicates.tsv` 4. Export data from OpenRefine project to tab-separated-values (TSV) file `duplicates.tsv`

9
orcli
View File

@ -887,10 +887,17 @@ orcli_transform_command() {
# support multiple files # support multiple files
for i in "${!files[@]}"; do for i in "${!files[@]}"; do
# read each operation into one line # read each operation into one line
mapfile -t jsonlines < <(jq -c '.[]' "${files[$i]}") if json="$(jq -c '.[]' "${files[$i]}")"; then
mapfile -t jsonlines <<<"$json"
else
error "parsing ${files[$i]} failed!"
fi
for line in "${jsonlines[@]}"; do for line in "${jsonlines[@]}"; do
# parse one line/operation into array # parse one line/operation into array
declare -A data="($(echo "$line" | jq -r 'to_entries | map("[\(.key)]=" + @sh "\(.value|tostring)") | .[]'))" declare -A data="($(echo "$line" | jq -r 'to_entries | map("[\(.key)]=" + @sh "\(.value|tostring)") | .[]'))"
if [[ ! ${data[op]} ]]; then
error "parsing ${files[$i]} failed!"
fi
# map operation names to command endpoints # map operation names to command endpoints
# https://github.com/OpenRefine/OpenRefine/blob/master/main/webapp/modules/core/MOD-INF/controller.js # https://github.com/OpenRefine/OpenRefine/blob/master/main/webapp/modules/core/MOD-INF/controller.js
com="${data[op]#core/}" com="${data[op]#core/}"

View File

@ -29,10 +29,17 @@ done
# support multiple files # support multiple files
for i in "${!files[@]}"; do for i in "${!files[@]}"; do
# read each operation into one line # read each operation into one line
mapfile -t jsonlines < <(jq -c '.[]' "${files[$i]}") if json="$(jq -c '.[]' "${files[$i]}")"; then
mapfile -t jsonlines <<<"$json"
else
error "parsing ${files[$i]} failed!"
fi
for line in "${jsonlines[@]}"; do for line in "${jsonlines[@]}"; do
# parse one line/operation into array # parse one line/operation into array
declare -A data="($(echo "$line" | jq -r 'to_entries | map("[\(.key)]=" + @sh "\(.value|tostring)") | .[]'))" declare -A data="($(echo "$line" | jq -r 'to_entries | map("[\(.key)]=" + @sh "\(.value|tostring)") | .[]'))"
if [[ ! ${data[op]} ]]; then
error "parsing ${files[$i]} failed!"
fi
# map operation names to command endpoints # map operation names to command endpoints
# https://github.com/OpenRefine/OpenRefine/blob/master/main/webapp/modules/core/MOD-INF/controller.js # https://github.com/OpenRefine/OpenRefine/blob/master/main/webapp/modules/core/MOD-INF/controller.js
com="${data[op]#core/}" com="${data[op]#core/}"