blob: 41d0c29702195e05798b2004b496fbdf0b76b914 [file] [log] [blame]
Corentin Wallez4a9ef4e2018-07-18 11:40:26 +02001// Copyright 2018 The Dawn Authors
Corentin Wallez1fda9802018-05-25 16:23:44 -04002//
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 Wallezd37523f2018-07-24 13:53:51 +020015#include "dawn_native/ErrorData.h"
Corentin Wallez1fda9802018-05-25 16:23:44 -040016
Austin Engcb0cb652019-08-27 21:41:56 +000017#include "dawn_native/Error.h"
18#include "dawn_native/dawn_platform.h"
19
Corentin Wallez49a65d02018-07-24 16:45:45 +020020namespace dawn_native {
Corentin Wallez1fda9802018-05-25 16:23:44 -040021
Rafael Cintron69c68d02020-01-10 17:58:28 +000022 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 Wallez1fda9802018-05-25 16:23:44 -040031
Austin Engcb0cb652019-08-27 21:41:56 +000032 ErrorData::ErrorData(InternalErrorType type, std::string message)
Corentin Wallez6fee61c2018-09-10 16:17:24 +020033 : mType(type), mMessage(std::move(message)) {
Corentin Wallez1fda9802018-05-25 16:23:44 -040034 }
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 Walleza0afd312020-04-01 12:07:43 +000045 InternalErrorType ErrorData::GetType() const {
Corentin Wallez6fee61c2018-09-10 16:17:24 +020046 return mType;
47 }
48
Corentin Wallez1fda9802018-05-25 16:23:44 -040049 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 Wallez49a65d02018-07-24 16:45:45 +020057} // namespace dawn_native