@@ -156,7 +156,11 @@ void JsonViewDlg::DrawJsonTree()
156156 }
157157 else
158158 {
159- PopulateTreeUsingSax (rootNode, txtForParsing);
159+ auto res = PopulateTreeUsingSax (rootNode, txtForParsing);
160+ if (res.has_value ())
161+ {
162+ ShowMessage (JSON_ERROR_TITLE, res.value (), MB_OK | MB_ICONERROR);
163+ }
160164 }
161165
162166 m_hTreeView->Expand (rootNode);
@@ -172,8 +176,10 @@ void JsonViewDlg::HightlightAsJson(bool bForcefully) const
172176 m_Editor->SetLangAsJson ();
173177}
174178
175- void JsonViewDlg::PopulateTreeUsingSax (HTREEITEM tree_root, const std::string &jsonText)
179+ auto JsonViewDlg::PopulateTreeUsingSax (HTREEITEM tree_root, const std::string &jsonText) -> std::optional<std::wstring>
176180{
181+ std::optional<std::wstring> retVal = std::nullopt ;
182+
177183 RapidJsonHandler handler (this , tree_root);
178184 rapidjson::StringBuffer sb;
179185
@@ -183,7 +189,7 @@ void JsonViewDlg::PopulateTreeUsingSax(HTREEITEM tree_root, const std::string &j
183189 // Intimate user
184190 if (jsonText.empty ())
185191 {
186- ShowMessage (JSON_ERROR_TITLE, JSON_ERR_PARSE, MB_OK | MB_ICONERROR );
192+ retVal = std::make_optional<std::wstring>(JSON_ERR_PARSE );
187193 }
188194 else
189195 {
@@ -193,13 +199,15 @@ void JsonViewDlg::PopulateTreeUsingSax(HTREEITEM tree_root, const std::string &j
193199 m_Editor->MakeSelection (errPosition, errPosition + 1 );
194200
195201 std::string err = std::format (" \n\n Error: ({} : {})" , res.error_code , res.error_str );
196- ShowMessage (JSON_ERROR_TITLE, ( JSON_ERR_VALIDATE + StringHelper::ToWstring (err)). c_str (), MB_OK | MB_ICONERROR );
202+ retVal = std::make_optional<std::wstring>(( JSON_ERR_VALIDATE + StringHelper::ToWstring (err)));
197203 }
198204 }
199205 else
200206 {
201207 HightlightAsJson ();
202208 }
209+
210+ return retVal;
203211}
204212
205213HTREEITEM JsonViewDlg::InsertToTree (HTREEITEM parent, const std::string &text)
0 commit comments