Corentin Wallez | 4a9ef4e | 2018-07-18 11:40:26 +0200 | [diff] [blame] | 1 | // Copyright 2018 The Dawn Authors |
Corentin Wallez | 1fda980 | 2018-05-25 16:23:44 -0400 | [diff] [blame] | 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
Corentin Wallez | d37523f | 2018-07-24 13:53:51 +0200 | [diff] [blame] | 15 | #include "dawn_native/ErrorData.h" |
Corentin Wallez | 1fda980 | 2018-05-25 16:23:44 -0400 | [diff] [blame] | 16 | |
Austin Eng | cb0cb65 | 2019-08-27 21:41:56 +0000 | [diff] [blame] | 17 | #include "dawn_native/Error.h" |
| 18 | #include "dawn_native/dawn_platform.h" |
| 19 | |
Corentin Wallez | 49a65d0 | 2018-07-24 16:45:45 +0200 | [diff] [blame] | 20 | namespace dawn_native { |
Corentin Wallez | 1fda980 | 2018-05-25 16:23:44 -0400 | [diff] [blame] | 21 | |
Rafael Cintron | 69c68d0 | 2020-01-10 17:58:28 +0000 | [diff] [blame] | 22 | std::unique_ptr<ErrorData> ErrorData::Create(InternalErrorType type, |
| 23 | std::string message, |
| 24 | const char* file, |
| 25 | const char* function, |
| 26 | int line) { |
| 27 | std::unique_ptr<ErrorData> error = std::make_unique<ErrorData>(type, message); |
| 28 | error->AppendBacktrace(file, function, line); |
| 29 | return error; |
| 30 | } |
Corentin Wallez | 1fda980 | 2018-05-25 16:23:44 -0400 | [diff] [blame] | 31 | |
Austin Eng | cb0cb65 | 2019-08-27 21:41:56 +0000 | [diff] [blame] | 32 | ErrorData::ErrorData(InternalErrorType type, std::string message) |
Corentin Wallez | 6fee61c | 2018-09-10 16:17:24 +0200 | [diff] [blame] | 33 | : mType(type), mMessage(std::move(message)) { |
Corentin Wallez | 1fda980 | 2018-05-25 16:23:44 -0400 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | void ErrorData::AppendBacktrace(const char* file, const char* function, int line) { |
| 37 | BacktraceRecord record; |
| 38 | record.file = file; |
| 39 | record.function = function; |
| 40 | record.line = line; |
| 41 | |
| 42 | mBacktrace.push_back(std::move(record)); |
| 43 | } |
| 44 | |
Corentin Wallez | a0afd31 | 2020-04-01 12:07:43 +0000 | [diff] [blame] | 45 | InternalErrorType ErrorData::GetType() const { |
Corentin Wallez | 6fee61c | 2018-09-10 16:17:24 +0200 | [diff] [blame] | 46 | return mType; |
| 47 | } |
| 48 | |
Corentin Wallez | 1fda980 | 2018-05-25 16:23:44 -0400 | [diff] [blame] | 49 | const std::string& ErrorData::GetMessage() const { |
| 50 | return mMessage; |
| 51 | } |
| 52 | |
| 53 | const std::vector<ErrorData::BacktraceRecord>& ErrorData::GetBacktrace() const { |
| 54 | return mBacktrace; |
| 55 | } |
| 56 | |
Corentin Wallez | 49a65d0 | 2018-07-24 16:45:45 +0200 | [diff] [blame] | 57 | } // namespace dawn_native |