From 6f0ab5754717362c485b61989bcbb61b8d5f15f2 Mon Sep 17 00:00:00 2001 From: Falke Design Date: Tue, 21 Sep 2021 10:42:50 +0200 Subject: [PATCH] Print error of `import-sql` at the end of the output (#1237) Because of the parallel processing of `import-sql` the error message is printed in the middle of the output. With this PR the error is displayed again at the end: ![grafik](https://user-images.githubusercontent.com/19800037/133897373-656ed3d0-e580-4f67-9290-0e83949d63d7.png) Issue: https://github.com/openmaptiles/openmaptiles-tools/pull/370 ``` awk '1{print; fflush()} $$0~".*ERROR" {txt=$$0} END{ if(txt){print "\n*** ERROR detected, aborting:"; print txt; exit(1)} }' ``` Explanation: - `1{print; fflush()}` means if true then print output -> `1{}` same as `if(true){}` - `$$0~".*ERROR" {txt=$$0}` get first argument `$$0` (line of output) and check if it contains (regex string) `ERROR`. If true save line to var `txt`: `{txt=$$0}` - `END{ ... }` if last line of output is reached - `if(txt){print "\n*** ERROR detected, aborting:"; print txt; exit(1)}` if error was found in a line / var `txt` is existing print it out --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 9f3caff9..26c169a4 100644 --- a/Makefile +++ b/Makefile @@ -420,7 +420,8 @@ endif .PHONY: import-sql import-sql: all start-db-nowait $(DOCKER_COMPOSE) run $(DC_OPTS) openmaptiles-tools sh -c 'pgwait && import-sql' | \ - awk -v s=": WARNING:" '1{print; fflush()} $$0~s{print "\n*** WARNING detected, aborting"; exit(1)}' + awk -v s=": WARNING:" '1{print; fflush()} $$0~s{print "\n*** WARNING detected, aborting"; exit(1)}' | \ + awk '1{print; fflush()} $$0~".*ERROR" {txt=$$0} END{ if(txt){print "\n*** ERROR detected, aborting:"; print txt; exit(1)} }' .PHONY: generate-tiles generate-tiles: all start-db