19
19
#define CHECK_OBJ_TYPE (obj , expected ) \
20
20
do { \
21
21
if ((obj)->type != (expected)) { \
22
- opal_show_help("help-json.txt", "Invalid argument type", true, __func__, #expected, \
23
- expected, (obj)->type); \
24
22
return OPAL_ERROR; \
25
23
} \
26
24
} while (0)
@@ -97,7 +95,6 @@ int opal_json_load(const char *str, const size_t len, const opal_json_t **json)
97
95
98
96
json_value * value = json_parse (str , len );
99
97
if (!value ) {
100
- opal_show_help ("help-json.txt" , "Invalid JSON string" , true);
101
98
ret = OPAL_ERROR ;
102
99
goto out ;
103
100
}
@@ -114,7 +111,7 @@ int opal_json_load(const char *str, const size_t len, const opal_json_t **json)
114
111
return ret ;
115
112
}
116
113
117
- int opal_json_load_file (const char * filename , const opal_json_t * * json )
114
+ int opal_json_load_file (const char * filename , const opal_json_t * * json , int show_errors )
118
115
{
119
116
FILE * fp = NULL ;
120
117
size_t file_size ;
@@ -123,7 +120,9 @@ int opal_json_load_file(const char *filename, const opal_json_t **json)
123
120
124
121
fp = fopen (filename , "r" );
125
122
if (fp == NULL ) {
126
- opal_show_help ("help-json.txt" , "Unable to open file" , true, filename );
123
+ if (show_errors ) {
124
+ opal_show_help ("help-json.txt" , "Unable to open file" , true, filename );
125
+ }
127
126
ret = OPAL_ERROR ;
128
127
goto out ;
129
128
}
@@ -134,18 +133,25 @@ int opal_json_load_file(const char *filename, const opal_json_t **json)
134
133
135
134
file_contents = (char * ) malloc (file_size );
136
135
if (!file_contents ) {
137
- opal_show_help ("help-json.txt" , "Memory allocation failure" , true);
136
+ if (show_errors ) {
137
+ opal_show_help ("help-json.txt" , "Memory allocation failure" , true);
138
+ }
138
139
ret = OPAL_ERROR ;
139
140
goto out ;
140
141
}
141
142
142
143
if (file_size > fread (file_contents , 1 , file_size , fp )) {
143
- opal_show_help ("help-json.txt" , "Unable to read file" , true, filename );
144
+ if (show_errors ) {
145
+ opal_show_help ("help-json.txt" , "Unable to read file" , true, filename );
146
+ }
144
147
ret = OPAL_ERROR ;
145
148
goto out ;
146
149
}
147
150
148
151
ret = opal_json_load (file_contents , file_size , json );
152
+ if (ret != OPAL_SUCCESS && show_errors ) {
153
+ opal_show_help ("help-json.txt" , "Invalid JSON string" , true);
154
+ }
149
155
150
156
out :
151
157
if (fp ) {
0 commit comments