From cc29ef351275dc356857cd080a8b798a75121fe7 Mon Sep 17 00:00:00 2001 From: Simon Brunel Date: Sat, 4 Jan 2020 13:05:09 +0100 Subject: [PATCH] Fix docs C++ snippet for the `.fail()` args - Fix the wrong lambda format (missing `[]`). - Make consistent argument naming (`error`). - Use `const &` when appropriated. --- docs/qtpromise/exceptions/canceled.md | 2 +- docs/qtpromise/exceptions/timeout.md | 2 +- docs/qtpromise/getting-started.md | 4 ++-- docs/qtpromise/helpers/attempt.md | 2 +- docs/qtpromise/helpers/connect.md | 6 +++--- docs/qtpromise/qpromise/fail.md | 13 ++++++++----- docs/qtpromise/qpromise/tapfail.md | 8 ++++---- docs/qtpromise/qpromise/timeout.md | 2 +- docs/qtpromise/qtconcurrent.md | 2 +- docs/qtpromise/qtsignals.md | 6 +++--- 10 files changed, 25 insertions(+), 22 deletions(-) diff --git a/docs/qtpromise/exceptions/canceled.md b/docs/qtpromise/exceptions/canceled.md index c61b532..792adb4 100644 --- a/docs/qtpromise/exceptions/canceled.md +++ b/docs/qtpromise/exceptions/canceled.md @@ -7,7 +7,7 @@ canceled (e.g. using [`QFuture::cancel()`](http://doc.qt.io/qt-5/qfuture.html#ca ```cpp auto output = QtPromise::resolve(future) - .fail([](const QPromiseCanceledException&) { + .fail([](const QPromiseCanceledException& error) { // `future` has been canceled! }); ``` diff --git a/docs/qtpromise/exceptions/timeout.md b/docs/qtpromise/exceptions/timeout.md index 832168f..af62bc4 100644 --- a/docs/qtpromise/exceptions/timeout.md +++ b/docs/qtpromise/exceptions/timeout.md @@ -8,7 +8,7 @@ This is the default exception thrown when reaching the time limit when using the ```cpp QPromise input = {...} auto output = input.timeout(2000) - .fail([](const QPromiseTimeoutException& e) { + .fail([](const QPromiseTimeoutException& error) { // operation timed out after 2s! }); ``` diff --git a/docs/qtpromise/getting-started.md b/docs/qtpromise/getting-started.md index e42cfc8..6608375 100644 --- a/docs/qtpromise/getting-started.md +++ b/docs/qtpromise/getting-started.md @@ -90,9 +90,9 @@ download(url).then(&uncompress).then([](const Entries& entries) { // {...} process entries }).finally([]() { // {...} cleanup -}).fail([](QNetworkReply::NetworkError err) { +}).fail([](QNetworkReply::NetworkError error) { // {...} handle network error -}).fail([](const UpdateException& err) { +}).fail([](const UpdateException& error) { // {...} handle update error }).fail([]() { // {...} catch all diff --git a/docs/qtpromise/helpers/attempt.md b/docs/qtpromise/helpers/attempt.md index e7c014d..f5ca5af 100644 --- a/docs/qtpromise/helpers/attempt.md +++ b/docs/qtpromise/helpers/attempt.md @@ -41,7 +41,7 @@ auto output = process(url); // 'output' type: QPromise output.then([](const QByteArray& res) { // {...} -}).fail([](const InvalidUrlException& err) { +}).fail([](const InvalidUrlException& error) { // {...} }); ``` diff --git a/docs/qtpromise/helpers/connect.md b/docs/qtpromise/helpers/connect.md index 425fee9..477469b 100644 --- a/docs/qtpromise/helpers/connect.md +++ b/docs/qtpromise/helpers/connect.md @@ -42,9 +42,9 @@ auto output = QtPromise::connect(sender, &Sender::finished, &Sender::error); // 'output' type: QPromise output.then([](const QByteArray& res) { // 'res' is the first argument of the 'finished' signal. -}).fail([](ErrorCode err) { - // 'err' is the first argument of the 'error' signal. -}).fail([](const QPromiseContextException& err) { +}).fail([](ErrorCode error) { + // 'error' is the first argument of the 'error' signal. +}).fail([](const QPromiseContextException& error) { // the 'sender' object has been destroyed before any of // the 'finished' or 'error' signals have been emitted. }); diff --git a/docs/qtpromise/qpromise/fail.md b/docs/qtpromise/qpromise/fail.md index 98e5a74..ca8e59a 100644 --- a/docs/qtpromise/qpromise/fail.md +++ b/docs/qtpromise/qpromise/fail.md @@ -10,16 +10,19 @@ title: .fail QPromise::fail(Function onRejected) -> QPromise ``` -Shorthand to `promise.then(nullptr, onRejected)`, similar to the [`catch` statement](http://en.cppreference.com/w/cpp/language/try_catch): +Shorthand to [`promise.then(nullptr, onRejected)`](then.md) for handling errors in promise chains, +similar to the native C++ [`catch` statement](http://en.cppreference.com/w/cpp/language/try_catch): ```cpp -promise.fail([](const MyException&) { +promise.fail([](const MyException& error) { // {...} -}).fail(const QException&) { +}).fail([](const QException& error) { // {...} -}).fail(const std::exception&) { +}).fail([](const std::exception& error) { // {...} -}).fail() { +}).fail([]() { // {...} catch-all }); ``` + +See also: [`QPromise::then`](then.md) diff --git a/docs/qtpromise/qpromise/tapfail.md b/docs/qtpromise/qpromise/tapfail.md index 99bf3bf..740a89c 100644 --- a/docs/qtpromise/qpromise/tapfail.md +++ b/docs/qtpromise/qpromise/tapfail.md @@ -17,12 +17,12 @@ rejected with the new exception. ```cpp QPromise input = {...} -auto output = input.tapFail([](Error err) { - log(err); +auto output = input.tapFail([](const Error& error) { + log(error); }).then([](int res) { return process(res); -}).fail([](Error err) { - handle(err); +}).fail([](const Error& error) { + handle(error); return -1; }); ``` diff --git a/docs/qtpromise/qpromise/timeout.md b/docs/qtpromise/qpromise/timeout.md index 08f36a4..99f3564 100644 --- a/docs/qtpromise/qpromise/timeout.md +++ b/docs/qtpromise/qpromise/timeout.md @@ -21,7 +21,7 @@ auto output = input.timeout(2000) .then([](int res) { // operation succeeded within 2 seconds }) - .fail([](const QPromiseTimeoutException& e) { + .fail([](const QPromiseTimeoutException& error) { // operation timed out! }); ``` diff --git a/docs/qtpromise/qtconcurrent.md b/docs/qtpromise/qtconcurrent.md index 943c612..9a9f0e8 100644 --- a/docs/qtpromise/qtconcurrent.md +++ b/docs/qtpromise/qtconcurrent.md @@ -67,7 +67,7 @@ promise.then([](int res) { return QString("42"); }); -}).fail(const CustomException& err) { +}).fail([](const CustomException& error) { // {...} }); ``` diff --git a/docs/qtpromise/qtsignals.md b/docs/qtpromise/qtsignals.md index 152eebc..2702c7f 100644 --- a/docs/qtpromise/qtsignals.md +++ b/docs/qtpromise/qtsignals.md @@ -53,7 +53,7 @@ auto output = QtPromise::connect(obj, &Object::finished, &Object::error); // output type: QPromise output.then([](const QByteArray& data) { // {...} -}).fail(const ObjectError& error) { +}).fail([](const ObjectError& error) { // {...} }); ``` @@ -69,7 +69,7 @@ auto output = QtPromise::connect(obj, &Object::finished, &Object::error); // output type: QPromise output.then([]() { // {...} -}).fail(const QPromiseUndefinedException& error) { +}).fail([](const QPromiseUndefinedException& error) { // {...} }); ``` @@ -84,7 +84,7 @@ auto output = QtPromise::connect(objA, &ObjectA::finished, objB, &ObjectB::error // output type: QPromise output.then([](const QByteArray& data) { // {...} -}).fail(const ObjectBError& error) { +}).fail([](const ObjectBError& error) { // {...} }); ```