From: Steven Baltakatei Sandoval <baltakatei@gmail.com>
Date: Mon, 29 Jan 2024 21:22:00 +0000 (+0000)
Subject: feat(unitproc/bkt-read_stdin):Add error handling
X-Git-Url: https://zdv2.bktei.com/gitweb/BK-2020-03.git/commitdiff_plain/c737bccf2824178671866e47416b1d405febdfe5?ds=inline

feat(unitproc/bkt-read_stdin):Add error handling
---

diff --git a/unitproc/bkt-read_stdin b/unitproc/bkt-read_stdin
index bf1873e..5df787b 100644
--- a/unitproc/bkt-read_stdin
+++ b/unitproc/bkt-read_stdin
@@ -12,13 +12,14 @@ read_stdin() {
     #         return  1  stdin not present
     # Example: printf "foo\nbar\n" | read_stdin
     # Depends: GNU bash (version 5.1.16), GNU Coreutils 8.32 (cat)
-    # Version: 0.1.0
+    # Version: 0.1.1
     # Attrib: Steven Baltakatei Sandoval (2024-01-29). reboil.com
     local input_stdin output;
 
     # Store stdin
     if [[ -p /dev/stdin ]]; then
-        input_stdin="$(cat -)";
+        input_stdin="$(cat -)" || {
+            echo "FATAL:Error reading stdin." 1>&2; return 1; };
     else
         return 1;
     fi; 
@@ -28,7 +29,8 @@ read_stdin() {
     if [[ -n $input_stdin ]]; then
         while read -r line; do
             output+=("$line");
-        done < <(printf "%s\n" "$input_stdin");
+        done < <(printf "%s\n" "$input_stdin") || {
+            echo "FATAL:Error parsing stdin."; return 1; };
     fi;
 
     # Print to stdout