Commit 29847171 authored by Christoph Cullmann's avatar Christoph Cullmann

improve JSON parsing error output for config dialog and normal reading

parent 098be905
......@@ -205,9 +205,13 @@ void LSPClientConfigPage::updateConfigTextErrorState()
// check json validity
QJsonParseError error;
QJsonDocument::fromJson(data, &error);
auto json = QJsonDocument::fromJson(data, &error);
if (error.error == QJsonParseError::NoError) {
ui->userConfigError->setText(i18n("JSON data is valid."));
if (json.isObject()) {
ui->userConfigError->setText(i18n("JSON data is valid."));
} else {
ui->userConfigError->setText(i18n("JSON data is invalid: no JSON object"));
}
} else {
ui->userConfigError->setText(i18n("JSON data is invalid: %1", error.errorString()));
}
......
......@@ -92,6 +92,7 @@
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonParseError>
#include <QRegularExpression>
#include <QTimer>
......@@ -606,11 +607,16 @@ private:
if (f.open(QIODevice::ReadOnly)) {
const auto data = f.readAll();
if (!data.isEmpty()) {
auto json = QJsonDocument::fromJson(data);
if (json.isObject()) {
m_serverConfig = merge(m_serverConfig, json.object());
QJsonParseError error;
auto json = QJsonDocument::fromJson(data, &error);
if (error.error == QJsonParseError::NoError) {
if (json.isObject()) {
m_serverConfig = merge(m_serverConfig, json.object());
} else {
showMessage(i18n("Failed to parse server configuration '%1': no JSON object", configPath), KTextEditor::Message::Error);
}
} else {
showMessage(i18n("Failed to parse server configuration: %1", configPath), KTextEditor::Message::Error);
showMessage(i18n("Failed to parse server configuration '%1': %2", configPath, error.errorString()), KTextEditor::Message::Error);
}
}
} else {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment