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>
This commit is contained in:
David Schulz
2022-12-16 06:03:09 +01:00
parent 1faae7dec4
commit c8e1201236
2 changed files with 5 additions and 1 deletions

View File

@@ -290,7 +290,10 @@ public:
return val.isUndefined() ? std::nullopt : std::make_optional(fromJsonValue<Error>(val)); return val.isUndefined() ? std::nullopt : std::make_optional(fromJsonValue<Error>(val));
} }
void setError(const Error &error) 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); } void clearError() { m_jsonObject.remove(errorKey); }
bool isValid(QString *errorMessage) const override bool isValid(QString *errorMessage) const override

View File

@@ -1891,6 +1891,7 @@ void ClientPrivate::handleMethod(const QString &method, const MessageId &id, con
Response<JsonObject, JsonObject> response(id); Response<JsonObject, JsonObject> response(id);
ResponseError<JsonObject> error; ResponseError<JsonObject> error;
error.setCode(ResponseError<JsonObject>::MethodNotFound); error.setCode(ResponseError<JsonObject>::MethodNotFound);
error.setMessage(QString("The client cannot handle the method '%1'.").arg(method));
response.setError(error); response.setError(error);
sendResponse(response); sendResponse(response);
} }