1 /** 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 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 PANDA_TOOLING_INSPECTOR_EXCEPTION_DETAILS_H 16 #define PANDA_TOOLING_INSPECTOR_EXCEPTION_DETAILS_H 17 18 #include "tooling/inspector/json_serialization/serializable.h" 19 20 #include <functional> 21 #include <optional> 22 #include <string> 23 24 #include "macros.h" 25 #include "types/numeric_id.h" 26 #include "types/remote_object.h" 27 28 namespace ark { 29 class JsonObjectBuilder; 30 } // namespace ark 31 32 namespace ark::tooling::inspector { 33 class ExceptionDetails final : public JsonSerializable { 34 public: ExceptionDetails(size_t exceptionId,std::string text,size_t lineNumber,size_t columnNumber)35 ExceptionDetails(size_t exceptionId, std::string text, size_t lineNumber, size_t columnNumber) 36 : exceptionId_(exceptionId), text_(std::move(text)), lineNumber_(lineNumber), columnNumber_(columnNumber) 37 { 38 } 39 40 void Serialize(JsonObjectBuilder &builder) const override; 41 GetExceptionId()42 size_t GetExceptionId() const 43 { 44 return exceptionId_; 45 } 46 GetText()47 const std::string &GetText() const 48 { 49 return text_; 50 } 51 GetLine()52 size_t GetLine() const 53 { 54 return lineNumber_; 55 } 56 GetColumn()57 size_t GetColumn() const 58 { 59 return columnNumber_; 60 } 61 GetScriptId()62 ScriptId GetScriptId() const 63 { 64 return scriptId_.value_or(0); 65 } 66 SetScriptId(ScriptId scriptId)67 ExceptionDetails &SetScriptId(ScriptId scriptId) 68 { 69 scriptId_ = scriptId; 70 return *this; 71 } 72 HasScriptId()73 bool HasScriptId() const 74 { 75 return scriptId_.has_value(); 76 } 77 GetUrl()78 const std::string &GetUrl() const 79 { 80 ASSERT(HasUrl()); 81 return url_.value(); 82 } 83 SetUrl(std::string_view url)84 ExceptionDetails &SetUrl(std::string_view url) 85 { 86 url_ = url; 87 return *this; 88 } 89 HasUrl()90 bool HasUrl() const 91 { 92 return url_.has_value(); 93 } 94 GetExceptionObject()95 const std::optional<RemoteObject> &GetExceptionObject() const 96 { 97 return exception_; 98 } 99 SetExceptionObject(RemoteObject && exception)100 ExceptionDetails &SetExceptionObject(RemoteObject &&exception) 101 { 102 exception_ = std::move(exception); 103 return *this; 104 } 105 HasExceptionObject()106 bool HasExceptionObject() const 107 { 108 return exception_.has_value(); 109 } 110 GetExecutionContextId()111 ExecutionContextId GetExecutionContextId() const 112 { 113 return executionContextId_.value_or(-1); 114 } 115 SetExecutionContextId(ExecutionContextId executionContextId)116 ExceptionDetails &SetExecutionContextId(ExecutionContextId executionContextId) 117 { 118 executionContextId_ = executionContextId; 119 return *this; 120 } 121 HasExecutionContextId()122 bool HasExecutionContextId() const 123 { 124 return executionContextId_.has_value(); 125 } 126 127 private: 128 size_t exceptionId_ {0}; 129 std::string text_; 130 size_t lineNumber_ {0}; 131 size_t columnNumber_ {0}; 132 std::optional<ScriptId> scriptId_; 133 std::optional<std::string> url_; 134 std::optional<RemoteObject> exception_; 135 std::optional<ExecutionContextId> executionContextId_; 136 }; 137 } // namespace ark::tooling::inspector 138 139 #endif // PANDA_TOOLING_INSPECTOR_EXCEPTION_DETAILS_H 140