Skip to content

Commit 42bb57d

Browse files
committed
refactor: Add 'existing' to error messages
1 parent 68fd135 commit 42bb57d

File tree

5 files changed

+19
-20
lines changed

5 files changed

+19
-20
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,4 @@ bpm add hyperupcall/bash-object
6262
- error on invalid references (`type=object` in virtual object metadata, when it is referencing an array)
6363
- add tests for array in array (like object in object)
6464
- ensure error (for set primarily) if the virtual object references a variable that does not exist
65-
- "queried for X, but found object": print object in error (same with indexed arrays)
65+
- "queried for X, but found existing object": print object in error (same with indexed arrays)

pkg/lib/traverse-get.sh

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ bash_object.traverse-get() {
9292
done
9393
;;
9494
array)
95-
# TODO: prepend 'existing' for all (existing array)
96-
bash_object.util.traverse_fail 'ERROR_VALUE_INCORRECT_TYPE' 'Queried for object, but found array'
95+
bash_object.util.traverse_fail 'ERROR_VALUE_INCORRECT_TYPE' 'Queried for object, but found existing array'
9796
return
9897
;;
9998
*)
@@ -104,7 +103,7 @@ bash_object.traverse-get() {
104103
elif [ "$final_value_type" = array ]; then
105104
case "$vmd_dtype" in
106105
object)
107-
bash_object.util.traverse_fail 'ERROR_VALUE_INCORRECT_TYPE' 'Queried for array, but found object'
106+
bash_object.util.traverse_fail 'ERROR_VALUE_INCORRECT_TYPE' 'Queried for array, but found existing object'
108107
return
109108
;;
110109
array)
@@ -120,11 +119,11 @@ bash_object.traverse-get() {
120119
elif [ "$final_value_type" = string ]; then
121120
case "$vmd_dtype" in
122121
object)
123-
bash_object.util.traverse_fail 'ERROR_VALUE_INCORRECT_TYPE' 'Queried for string, but found object'
122+
bash_object.util.traverse_fail 'ERROR_VALUE_INCORRECT_TYPE' 'Queried for string, but found existing object'
124123
return
125124
;;
126125
array)
127-
bash_object.util.traverse_fail 'ERROR_VALUE_INCORRECT_TYPE' 'Queried for string, but found array'
126+
bash_object.util.traverse_fail 'ERROR_VALUE_INCORRECT_TYPE' 'Queried for string, but found existing array'
128127
return
129128
;;
130129
*)
@@ -151,10 +150,10 @@ bash_object.traverse-get() {
151150
elif ((i+1 == ${#REPLIES[@]})); then
152151
local value="${current_object["$key"]}"
153152
if [ "$final_value_type" = object ]; then
154-
bash_object.util.traverse_fail 'ERROR_VALUE_INCORRECT_TYPE' "Queried for object, but found string '$value'"
153+
bash_object.util.traverse_fail 'ERROR_VALUE_INCORRECT_TYPE' "Queried for object, but found existing string '$value'"
155154
return
156155
elif [ "$final_value_type" = array ]; then
157-
bash_object.util.traverse_fail 'ERROR_VALUE_INCORRECT_TYPE' "Queried for array, but found string '$value'"
156+
bash_object.util.traverse_fail 'ERROR_VALUE_INCORRECT_TYPE' "Queried for array, but found existing string '$value'"
158157
return
159158
elif [ "$final_value_type" = string ]; then
160159
# shellcheck disable=SC2178

tests/get-array.bats

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ load './util/init.sh'
99

1010
assert_failure
1111
assert_line -p "ERROR_VALUE_INCORRECT_TYPE"
12-
assert_line -p 'Queried for array, but found string'
12+
assert_line -p 'Queried for array, but found existing string'
1313
}
1414

1515
@test "ERROR_VALUE_INCORRECT_TYPE on get-array'ing string in object" {
@@ -20,7 +20,7 @@ load './util/init.sh'
2020

2121
assert_failure
2222
assert_line -p "ERROR_VALUE_INCORRECT_TYPE"
23-
assert_line -p 'Queried for array, but found string'
23+
assert_line -p 'Queried for array, but found existing string'
2424
}
2525

2626
@test "ERROR_VALUE_INCORRECT_TYPE on get-array'ing object" {
@@ -31,7 +31,7 @@ load './util/init.sh'
3131

3232
assert_failure
3333
assert_line -p "ERROR_VALUE_INCORRECT_TYPE"
34-
assert_line -p 'Queried for array, but found object'
34+
assert_line -p 'Queried for array, but found existing object'
3535
}
3636

3737
@test "ERROR_VALUE_INCORRECT_TYPE on get-array'ing object in object" {
@@ -43,7 +43,7 @@ load './util/init.sh'
4343

4444
assert_failure
4545
assert_line -p "ERROR_VALUE_INCORRECT_TYPE"
46-
assert_line -p 'Queried for array, but found object'
46+
assert_line -p 'Queried for array, but found existing object'
4747
}
4848

4949
@test "correctly gets array" {

tests/get-object.bats

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ load './util/init.sh'
99

1010
assert_failure
1111
assert_line -p "ERROR_VALUE_INCORRECT_TYPE"
12-
assert_line -p 'Queried for object, but found string'
12+
assert_line -p 'Queried for object, but found existing string'
1313
}
1414

1515
@test "ERROR_VALUE_INCORRECT_TYPE on get-object'ing string inside object" {
@@ -20,7 +20,7 @@ load './util/init.sh'
2020

2121
assert_failure
2222
assert_line -p "ERROR_VALUE_INCORRECT_TYPE"
23-
assert_line -p 'Queried for object, but found string'
23+
assert_line -p 'Queried for object, but found existing string'
2424
}
2525

2626
@test "ERROR_VALUE_INCORRECT_TYPE on get-object'ing array" {
@@ -31,7 +31,7 @@ load './util/init.sh'
3131

3232
assert_failure
3333
assert_line -p "ERROR_VALUE_INCORRECT_TYPE"
34-
assert_line -p 'Queried for object, but found array'
34+
assert_line -p 'Queried for object, but found existing array'
3535
}
3636

3737
@test "ERROR_VALUE_INCORRECT_TYPE on get-object'ing array inside object" {
@@ -43,7 +43,7 @@ load './util/init.sh'
4343

4444
assert_failure
4545
assert_line -p "ERROR_VALUE_INCORRECT_TYPE"
46-
assert_line -p 'Queried for object, but found array'
46+
assert_line -p 'Queried for object, but found existing array'
4747
}
4848

4949
@test "correctly gets object" {

tests/get-string.bats

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ load './util/init.sh'
1010

1111
assert_failure
1212
assert_line -p "ERROR_VALUE_INCORRECT_TYPE"
13-
assert_line -p 'Queried for string, but found object'
13+
assert_line -p 'Queried for string, but found existing object'
1414
}
1515

1616
@test "ERROR_VALUE_INCORRECT_TYPE on get-string'ing object in object" {
@@ -22,7 +22,7 @@ load './util/init.sh'
2222

2323
assert_failure
2424
assert_line -p "ERROR_VALUE_INCORRECT_TYPE"
25-
assert_line -p 'Queried for string, but found object'
25+
assert_line -p 'Queried for string, but found existing object'
2626
}
2727

2828
@test "ERROR_VALUE_INCORRECT_TYPE on get-string'ing array" {
@@ -33,7 +33,7 @@ load './util/init.sh'
3333

3434
assert_failure
3535
assert_line -p "ERROR_VALUE_INCORRECT_TYPE"
36-
assert_line -p 'Queried for string, but found array'
36+
assert_line -p 'Queried for string, but found existing array'
3737
}
3838

3939
@test "ERROR_VALUE_INCORRECT_TYPE on get-string'ing array in object" {
@@ -45,7 +45,7 @@ load './util/init.sh'
4545

4646
assert_failure
4747
assert_line -p "ERROR_VALUE_INCORRECT_TYPE"
48-
assert_line -p 'Queried for string, but found array'
48+
assert_line -p 'Queried for string, but found existing array'
4949
}
5050

5151
@test "correctly gets object at root" {

0 commit comments

Comments
 (0)