diff options
author | David Schulz <david.schulz@qt.io> | 2022-12-16 06:03:09 +0100 |
---|---|---|
committer | David Schulz <david.schulz@qt.io> | 2022-12-16 07:05:55 +0000 |
commit | c8e120123671bfe25fb508508f796714e2b42622 (patch) | |
tree | baa57e226c86da61a5e024cdaa5e5cbbaf364072 | |
parent | 1faae7dec412b947f8a0a03c18b50e16eab83f4f (diff) |
LanguageClient: Do not send out invalid errors
An error is expected to contain an error message so add one that misses
one. Additionally assert when trying to set an error to a response that
is invalid (does not contain message or code.)
Fixes: QTCREATORBUG-28598
Fixes: QTCREATORBUG-27856
Change-Id: I0631433d847610531758d297a93a5c7cdfdc6c1d
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
-rw-r--r-- | src/libs/languageserverprotocol/jsonrpcmessages.h | 5 | ||||
-rw-r--r-- | src/plugins/languageclient/client.cpp | 1 |
2 files changed, 5 insertions, 1 deletions
diff --git a/src/libs/languageserverprotocol/jsonrpcmessages.h b/src/libs/languageserverprotocol/jsonrpcmessages.h index ebf51b4c14..c33e46422c 100644 --- a/src/libs/languageserverprotocol/jsonrpcmessages.h +++ b/src/libs/languageserverprotocol/jsonrpcmessages.h @@ -290,7 +290,10 @@ public: return val.isUndefined() ? std::nullopt : std::make_optional(fromJsonValue<Error>(val)); } void setError(const Error &error) - { m_jsonObject.insert(errorKey, QJsonValue(error)); } + { + QTC_CHECK(error.isValid()); + m_jsonObject.insert(errorKey, QJsonValue(error)); + } void clearError() { m_jsonObject.remove(errorKey); } bool isValid(QString *errorMessage) const override diff --git a/src/plugins/languageclient/client.cpp b/src/plugins/languageclient/client.cpp index 5c99329675..aca6ab5009 100644 --- a/src/plugins/languageclient/client.cpp +++ b/src/plugins/languageclient/client.cpp @@ -1891,6 +1891,7 @@ void ClientPrivate::handleMethod(const QString &method, const MessageId &id, con Response<JsonObject, JsonObject> response(id); ResponseError<JsonObject> error; error.setCode(ResponseError<JsonObject>::MethodNotFound); + error.setMessage(QString("The client cannot handle the method '%1'.").arg(method)); response.setError(error); sendResponse(response); } |