Skip to content

Commit 888a7d3

Browse files
committed
feat: Add core.print_die_fn(). Closes #11
1 parent feaca30 commit 888a7d3

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

docs/api.md

+10
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Core functions for any Bash program
1515
* [core.err_exists()](#coreerr_exists)
1616
* [core.panic()](#corepanic)
1717
* [core.print_stacktrace()](#coreprint_stacktrace)
18+
* [core.print_die_fn()](#coreprint_die_fn)
1819
* [core.print_fatal_fn()](#coreprint_fatal_fn)
1920
* [core.print_error_fn()](#coreprint_error_fn)
2021
* [core.print_warn_fn()](#coreprint_warn_fn)
@@ -159,6 +160,15 @@ core.trap_add 'err_handler' ERR
159160

160161
_Function has no arguments._
161162

163+
### core.print_die_fn()
164+
165+
Print a error message to standard error including the function name
166+
of the callee to standard error and die
167+
168+
#### Arguments
169+
170+
* **$1** (string): message
171+
162172
### core.print_fatal_fn()
163173

164174
Print a fatal error message including the function name of the callee

pkg/src/public/bash-core.sh

+9
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,15 @@ core.print_stacktrace() {
283283
fi
284284
} >&2
285285

286+
# @description Print a error message to standard error including the function name
287+
# of the callee to standard error and die
288+
# @arg $1 string message
289+
core.print_die_fn() {
290+
local msg="$1"
291+
292+
core.print_die "${FUNCNAME[1]}()${msg:+": "}$msg"
293+
}
294+
286295
# @description Print a fatal error message including the function name of the callee
287296
# to standard error
288297
# @arg $1 string message

0 commit comments

Comments
 (0)