1919#define CHECK_OBJ_TYPE (obj , expected ) \
2020 do { \
2121 if ((obj)->type != (expected)) { \
22- opal_show_help("help-json.txt", "Invalid argument type", true, __func__, #expected, \
23- expected, (obj)->type); \
2422 return OPAL_ERROR; \
2523 } \
2624 } while (0)
@@ -97,7 +95,6 @@ int opal_json_load(const char *str, const size_t len, const opal_json_t **json)
9795
9896 json_value * value = json_parse (str , len );
9997 if (!value ) {
100- opal_show_help ("help-json.txt" , "Invalid JSON string" , true);
10198 ret = OPAL_ERROR ;
10299 goto out ;
103100 }
@@ -114,7 +111,7 @@ int opal_json_load(const char *str, const size_t len, const opal_json_t **json)
114111 return ret ;
115112}
116113
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 )
118115{
119116 FILE * fp = NULL ;
120117 size_t file_size ;
@@ -123,7 +120,9 @@ int opal_json_load_file(const char *filename, const opal_json_t **json)
123120
124121 fp = fopen (filename , "r" );
125122 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+ }
127126 ret = OPAL_ERROR ;
128127 goto out ;
129128 }
@@ -134,18 +133,25 @@ int opal_json_load_file(const char *filename, const opal_json_t **json)
134133
135134 file_contents = (char * ) malloc (file_size );
136135 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+ }
138139 ret = OPAL_ERROR ;
139140 goto out ;
140141 }
141142
142143 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+ }
144147 ret = OPAL_ERROR ;
145148 goto out ;
146149 }
147150
148151 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+ }
149155
150156out :
151157 if (fp ) {
0 commit comments