forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Impeller] Started throwing errors if dart:ui/Image.toByteData fails (f…
…lutter#46738) issue: flutter/flutter#135245 This is a first step. Next we'll implement a retry. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide] and the [C++, Objective-C, Java style guides]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I added new tests to check the change I am making or feature I am adding, or the PR is [test-exempt]. See [testing the engine] for instructions on writing and running engine tests. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I signed the [CLA]. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/wiki/Tree-hygiene#overview [Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene [test-exempt]: https://github.com/flutter/flutter/wiki/Tree-hygiene#tests [Flutter Style Guide]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style [testing the engine]: https://github.com/flutter/flutter/wiki/Testing-the-engine [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/wiki/Chat
- Loading branch information
Showing
10 changed files
with
268 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef FLUTTER_FML_STATUS_OR_H_ | ||
#define FLUTTER_FML_STATUS_OR_H_ | ||
|
||
#include <optional> | ||
|
||
#include "flutter/fml/status.h" | ||
|
||
namespace fml { | ||
|
||
// TODO(https://github.com/flutter/flutter/issues/134741): Replace with | ||
// absl::StatusOr. | ||
/// Represents a union type of an object of type `T` and an fml::Status. | ||
/// | ||
/// This is often used as a replacement for C++ exceptions where a function that | ||
/// could fail may return an error or a result. These are typically used for | ||
/// errors that are meant to be recovered from. If there is no recovery | ||
/// available `FML_CHECK` is more appropriate. | ||
/// | ||
/// Example: | ||
/// StatusOr<int> div(int n, int d) { | ||
/// if (d == 0) { | ||
/// return Status(StatusCode::kFailedPrecondition, "div by zero"); | ||
/// } | ||
/// return n / d; | ||
/// } | ||
template <typename T> | ||
class StatusOr { | ||
public: | ||
StatusOr(const T& value) : status_(), value_(value) {} | ||
StatusOr(const Status& status) : status_(status), value_() {} | ||
|
||
StatusOr(const StatusOr&) = default; | ||
StatusOr(StatusOr&&) = default; | ||
|
||
StatusOr& operator=(const StatusOr&) = default; | ||
StatusOr& operator=(StatusOr&&) = default; | ||
|
||
StatusOr& operator=(const T& value) { | ||
status_ = Status(); | ||
value_ = value; | ||
return *this; | ||
} | ||
|
||
StatusOr& operator=(const T&& value) { | ||
status_ = Status(); | ||
value_ = std::move(value); | ||
return *this; | ||
} | ||
|
||
StatusOr& operator=(const Status& value) { | ||
status_ = value; | ||
value_ = std::nullopt; | ||
return *this; | ||
} | ||
|
||
const Status& status() const { return status_; } | ||
|
||
bool ok() const { return status_.ok(); } | ||
|
||
const T& value() const { | ||
FML_CHECK(status_.ok()); | ||
return value_.value(); | ||
} | ||
|
||
T& value() { | ||
FML_CHECK(status_.ok()); | ||
return value_.value(); | ||
} | ||
|
||
private: | ||
Status status_; | ||
std::optional<T> value_; | ||
}; | ||
|
||
} // namespace fml | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.