Skip to content

Commit fd29ee2

Browse files
committed
deprecate: Error functions
1 parent bf5de2f commit fd29ee2

File tree

2 files changed

+78
-78
lines changed

2 files changed

+78
-78
lines changed

docs/api.md

+36-36
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ Core functions for any Bash program
1010
* [core.trap_remove](#coretrap_remove)
1111
* [core.shopt_push](#coreshopt_push)
1212
* [core.shopt_pop](#coreshopt_pop)
13-
* [core.err_set](#coreerr_set)
14-
* [core.err_clear](#coreerr_clear)
15-
* [core.err_exists](#coreerr_exists)
1613
* [core.panic](#corepanic)
1714
* [core.print_stacktrace](#coreprint_stacktrace)
1815
* [core.print_fatal_fn](#coreprint_fatal_fn)
@@ -25,6 +22,9 @@ Core functions for any Bash program
2522
* [core.print_warn](#coreprint_warn)
2623
* [core.print_info](#coreprint_info)
2724
* [core.print_debug](#coreprint_debug)
25+
* [core.err_set](#coreerr_set)
26+
* [core.err_clear](#coreerr_clear)
27+
* [core.err_exists](#coreerr_exists)
2828
* [core.should_output_color](#coreshould_output_color)
2929
* [core.get_package_info](#coreget_package_info)
3030
* [core.init](#coreinit)
@@ -104,39 +104,6 @@ core.shopt_pop
104104

105105
_Function has no arguments._
106106

107-
### core.err_set
108-
109-
Sets an error.
110-
111-
#### Arguments
112-
113-
* **$1** (Error): code
114-
* **$2** (Error): message
115-
116-
#### Variables set
117-
118-
* **number** (ERRCODE): Error code
119-
* **string** (ERR): Error message
120-
121-
### core.err_clear
122-
123-
Clears any of the global error state (sets to empty string).
124-
This means any `core.err_exists` calls after this _will_ `return 1`
125-
126-
_Function has no arguments._
127-
128-
#### Variables set
129-
130-
* **number** (ERRCODE): Error code
131-
* **string** (ERR): Error message
132-
133-
### core.err_exists
134-
135-
Checks if an error exists. If `ERR` is not empty, then an error
136-
_does_ exist
137-
138-
_Function has no arguments._
139-
140107
### core.panic
141108

142109
Use when a serious fault occurs. It will print the current ERR (if it exists)
@@ -245,6 +212,39 @@ Print a debug message to standard output if the environment variable "DEBUG" is
245212

246213
* **$1** (string): message
247214

215+
### core.err_set
216+
217+
(DEPRECATED) Sets an error.
218+
219+
#### Arguments
220+
221+
* **$1** (Error): code
222+
* **$2** (Error): message
223+
224+
#### Variables set
225+
226+
* **number** (ERRCODE): Error code
227+
* **string** (ERR): Error message
228+
229+
### core.err_clear
230+
231+
(DEPRECATED) Clears any of the global error state (sets to empty string).
232+
This means any `core.err_exists` calls after this _will_ `return 1`
233+
234+
_Function has no arguments._
235+
236+
#### Variables set
237+
238+
* **number** (ERRCODE): Error code
239+
* **string** (ERR): Error message
240+
241+
### core.err_exists
242+
243+
(DEPRECATED) Checks if an error exists. If `ERR` is not empty, then an error
244+
_does_ exist
245+
246+
_Function has no arguments._
247+
248248
### core.should_output_color
249249

250250
(DEPRECATED). Determine if color should be printed. Note that this doesn't

pkg/src/public/bash-core.sh

+42-42
Original file line numberDiff line numberDiff line change
@@ -168,48 +168,6 @@ core.shopt_pop() {
168168
___global_shopt_stack___=("${___global_shopt_stack___[@]::${#___global_shopt_stack___[@]}-2}")
169169
}
170170

171-
# @description Sets an error.
172-
# @arg $1 Error code
173-
# @arg $2 Error message
174-
# @set number ERRCODE Error code
175-
# @set string ERR Error message
176-
core.err_set() {
177-
if (($# == 1)); then
178-
ERRCODE=1
179-
ERR=$1
180-
elif (($# == 2)); then
181-
ERRCODE=$1
182-
ERR=$2
183-
else
184-
core.panic 'Incorrect function arguments'
185-
fi
186-
187-
if [ -z "$ERR" ]; then
188-
core.panic "Argument for 'ERR' cannot be empty"
189-
fi
190-
}
191-
192-
# @description Clears any of the global error state (sets to empty string).
193-
# This means any `core.err_exists` calls after this _will_ `return 1`
194-
# @noargs
195-
# @set number ERRCODE Error code
196-
# @set string ERR Error message
197-
core.err_clear() {
198-
ERRCODE=
199-
ERR=
200-
}
201-
202-
# @description Checks if an error exists. If `ERR` is not empty, then an error
203-
# _does_ exist
204-
# @noargs
205-
core.err_exists() {
206-
if [ -z "$ERR" ]; then
207-
return 1
208-
else
209-
return 0
210-
fi
211-
}
212-
213171
# @description Use when a serious fault occurs. It will print the current ERR (if it exists)
214172
core.panic() {
215173
local code='1'
@@ -391,6 +349,48 @@ core.ifs_restore() {
391349
IFS=$___global_ifs_variable_saved___
392350
}
393351

352+
# @description (DEPRECATED) Sets an error.
353+
# @arg $1 Error code
354+
# @arg $2 Error message
355+
# @set number ERRCODE Error code
356+
# @set string ERR Error message
357+
core.err_set() {
358+
if (($# == 1)); then
359+
ERRCODE=1
360+
ERR=$1
361+
elif (($# == 2)); then
362+
ERRCODE=$1
363+
ERR=$2
364+
else
365+
core.panic 'Incorrect function arguments'
366+
fi
367+
368+
if [ -z "$ERR" ]; then
369+
core.panic "Argument for 'ERR' cannot be empty"
370+
fi
371+
}
372+
373+
# @description (DEPRECATED) Clears any of the global error state (sets to empty string).
374+
# This means any `core.err_exists` calls after this _will_ `return 1`
375+
# @noargs
376+
# @set number ERRCODE Error code
377+
# @set string ERR Error message
378+
core.err_clear() {
379+
ERRCODE=
380+
ERR=
381+
}
382+
383+
# @description (DEPRECATED) Checks if an error exists. If `ERR` is not empty, then an error
384+
# _does_ exist
385+
# @noargs
386+
core.err_exists() {
387+
if [ -z "$ERR" ]; then
388+
return 1
389+
else
390+
return 0
391+
fi
392+
}
393+
394394
# @description (DEPRECATED). Determine if color should be printed. Note that this doesn't
395395
# use tput because simple environment variable checking heuristics suffice. Deprecated because this code
396396
# has been moved to bash-std

0 commit comments

Comments
 (0)