|
| 1 | +/* |
| 2 | + * Copyright 2026 Wanaku AI |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package ai.wanaku.capabilities.sdk.api.types.execution; |
| 17 | + |
| 18 | +import com.fasterxml.jackson.annotation.JsonProperty; |
| 19 | +import java.util.Map; |
| 20 | + |
| 21 | +/** |
| 22 | + * Error response DTO for code execution failures. |
| 23 | + * <p> |
| 24 | + * This class represents error responses returned by the code execution |
| 25 | + * endpoints when validation fails, tasks are not found, or execution |
| 26 | + * errors occur. |
| 27 | + * </p> |
| 28 | + */ |
| 29 | +public class CodeExecutionError { |
| 30 | + |
| 31 | + /** |
| 32 | + * The error type or category. |
| 33 | + * Examples: "VALIDATION_ERROR", "NOT_FOUND", "EXECUTION_ERROR", "TIMEOUT" |
| 34 | + */ |
| 35 | + @JsonProperty("error") |
| 36 | + private String error; |
| 37 | + |
| 38 | + /** |
| 39 | + * Human-readable error message describing what went wrong. |
| 40 | + */ |
| 41 | + @JsonProperty("message") |
| 42 | + private String message; |
| 43 | + |
| 44 | + /** |
| 45 | + * The task ID if applicable. |
| 46 | + * Present when the error relates to a specific task. |
| 47 | + */ |
| 48 | + @JsonProperty("taskId") |
| 49 | + private String taskId; |
| 50 | + |
| 51 | + /** |
| 52 | + * The timestamp when the error occurred (Unix timestamp in milliseconds). |
| 53 | + */ |
| 54 | + @JsonProperty("timestamp") |
| 55 | + private Long timestamp; |
| 56 | + |
| 57 | + /** |
| 58 | + * Additional error details as key-value pairs. |
| 59 | + * Can include field-specific validation errors, stack traces, etc. |
| 60 | + */ |
| 61 | + @JsonProperty("details") |
| 62 | + private Map<String, String> details; |
| 63 | + |
| 64 | + /** |
| 65 | + * Default constructor for JSON serialization. |
| 66 | + */ |
| 67 | + public CodeExecutionError() { |
| 68 | + this.timestamp = System.currentTimeMillis(); |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * Constructor with error type and message. |
| 73 | + * |
| 74 | + * @param error the error type |
| 75 | + * @param message the error message |
| 76 | + */ |
| 77 | + public CodeExecutionError(String error, String message) { |
| 78 | + this.error = error; |
| 79 | + this.message = message; |
| 80 | + this.timestamp = System.currentTimeMillis(); |
| 81 | + } |
| 82 | + |
| 83 | + /** |
| 84 | + * Constructor with all fields except details. |
| 85 | + * |
| 86 | + * @param error the error type |
| 87 | + * @param message the error message |
| 88 | + * @param taskId the task ID |
| 89 | + */ |
| 90 | + public CodeExecutionError(String error, String message, String taskId) { |
| 91 | + this.error = error; |
| 92 | + this.message = message; |
| 93 | + this.taskId = taskId; |
| 94 | + this.timestamp = System.currentTimeMillis(); |
| 95 | + } |
| 96 | + |
| 97 | + // Getters and Setters |
| 98 | + |
| 99 | + public String getError() { |
| 100 | + return error; |
| 101 | + } |
| 102 | + |
| 103 | + public void setError(String error) { |
| 104 | + this.error = error; |
| 105 | + } |
| 106 | + |
| 107 | + public String getMessage() { |
| 108 | + return message; |
| 109 | + } |
| 110 | + |
| 111 | + public void setMessage(String message) { |
| 112 | + this.message = message; |
| 113 | + } |
| 114 | + |
| 115 | + public String getTaskId() { |
| 116 | + return taskId; |
| 117 | + } |
| 118 | + |
| 119 | + public void setTaskId(String taskId) { |
| 120 | + this.taskId = taskId; |
| 121 | + } |
| 122 | + |
| 123 | + public Long getTimestamp() { |
| 124 | + return timestamp; |
| 125 | + } |
| 126 | + |
| 127 | + public void setTimestamp(Long timestamp) { |
| 128 | + this.timestamp = timestamp; |
| 129 | + } |
| 130 | + |
| 131 | + public Map<String, String> getDetails() { |
| 132 | + return details; |
| 133 | + } |
| 134 | + |
| 135 | + public void setDetails(Map<String, String> details) { |
| 136 | + this.details = details; |
| 137 | + } |
| 138 | + |
| 139 | + @Override |
| 140 | + public String toString() { |
| 141 | + return "CodeExecutionError{" + "error='" |
| 142 | + + error + '\'' + ", message='" |
| 143 | + + message + '\'' + ", taskId='" |
| 144 | + + taskId + '\'' + ", timestamp=" |
| 145 | + + timestamp + ", details=" |
| 146 | + + details + '}'; |
| 147 | + } |
| 148 | +} |
0 commit comments