Skip to content

Commit 2e2c45b

Browse files
committed
COMMON: update json error message
1 parent b6674d5 commit 2e2c45b

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

src/common/sberr.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,10 @@ void err_array() {
367367
rt_raise(MSG_ARRAY_SE);
368368
}
369369

370+
void err_json(int pos) {
371+
err_throw(MSG_ERR_JSON, pos);
372+
}
373+
370374
void err_form_input() {
371375
err_throw(ERR_FORM_INPUT);
372376
}

src/common/sberr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ void err_run_err(const char *file);
7676
void err_ref_var();
7777
void err_ref_circ_var();
7878
void err_array();
79+
void err_json(int pos);
7980
void err_form_input();
8081
void err_memory();
8182
void err_network();

src/common/var_map.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ int map_create_array(var_p_t dest, JsonTokens *json, int end_position, int index
528528
list.head = NULL;
529529
list.tail = NULL;
530530

531-
while (i < json->num_tokens) {
531+
while (i < json->num_tokens && !prog_error) {
532532
jsmntok_t token = json->tokens[i];
533533
if (token.start > end_position) {
534534
break;
@@ -545,7 +545,7 @@ int map_create_array(var_p_t dest, JsonTokens *json, int end_position, int index
545545
cols = curcol;
546546
}
547547
}
548-
while (delim != NULL) {
548+
while (delim != NULL && !prog_error) {
549549
rows++;
550550
curcol = 0;
551551
len -= (delim - str) + 1;
@@ -583,7 +583,7 @@ int map_create_array(var_p_t dest, JsonTokens *json, int end_position, int index
583583
int map_create(var_p_t dest, JsonTokens *json, int end_position, int index) {
584584
hashmap_create(dest, 0);
585585
int i = index;
586-
while (i < json->num_tokens) {
586+
while (i < json->num_tokens && !prog_error) {
587587
jsmntok_t token = json->tokens[i];
588588
if (token.start > end_position) {
589589
break;
@@ -593,7 +593,12 @@ int map_create(var_p_t dest, JsonTokens *json, int end_position, int index) {
593593
var_p_t value = hashmap_putv(dest, key);
594594
i = map_read_next_token(value, json, i + 1);
595595
} else {
596-
err_array();
596+
int position = token.start;
597+
if (i > 0) {
598+
// error near end of previous token
599+
position = json->tokens[i - 1].start;
600+
}
601+
err_json(position);
597602
break;
598603
}
599604
}

src/languages/messages.en.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@
124124
#define MSG_MISSING_ENDTRY "TRY without END TRY"
125125
#define MSG_FUNC_NOT_ASSIGNED "The value returned from %s was not assigned"
126126
#define MSG_RETURN_NOT_ASSIGNED "FUNC (line %d) - result not assigned"
127+
#define MSG_ERR_JSON "JSON decode error. Error near position [%d]"
127128

128129
// executor
129130
#define WORD_ERROR_AT "ERROR AT"

0 commit comments

Comments
 (0)