• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 The Dawn Authors
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 
15 #ifndef DAWNNATIVE_ERRORDATA_H_
16 #define DAWNNATIVE_ERRORDATA_H_
17 
18 #include "common/Compiler.h"
19 
20 #include <cstdint>
21 #include <memory>
22 #include <string>
23 #include <vector>
24 
25 namespace wgpu {
26     enum class ErrorType : uint32_t;
27 }
28 
29 namespace dawn {
30     using ErrorType = wgpu::ErrorType;
31 }
32 
33 namespace dawn_native {
34     enum class InternalErrorType : uint32_t;
35 
36     class DAWN_NO_DISCARD ErrorData {
37       public:
38         static DAWN_NO_DISCARD std::unique_ptr<ErrorData> Create(InternalErrorType type,
39                                                                  std::string message,
40                                                                  const char* file,
41                                                                  const char* function,
42                                                                  int line);
43         ErrorData(InternalErrorType type, std::string message);
44 
45         struct BacktraceRecord {
46             const char* file;
47             const char* function;
48             int line;
49         };
50         void AppendBacktrace(const char* file, const char* function, int line);
51         void AppendContext(std::string context);
52         void AppendDebugGroup(std::string label);
53 
54         InternalErrorType GetType() const;
55         const std::string& GetMessage() const;
56         const std::vector<BacktraceRecord>& GetBacktrace() const;
57         const std::vector<std::string>& GetContexts() const;
58         const std::vector<std::string>& GetDebugGroups() const;
59 
60         std::string GetFormattedMessage() const;
61 
62       private:
63         InternalErrorType mType;
64         std::string mMessage;
65         std::vector<BacktraceRecord> mBacktrace;
66         std::vector<std::string> mContexts;
67         std::vector<std::string> mDebugGroups;
68     };
69 
70 }  // namespace dawn_native
71 
72 #endif  // DAWNNATIVE_ERRORDATA_H_
73