Skip to content

Commit 5365a3f

Browse files
elliotttJakeChampion
authored andcommitted
Move the constructor for FastlySendError out of host_api.h
1 parent 58ddb20 commit 5365a3f

File tree

2 files changed

+125
-117
lines changed

2 files changed

+125
-117
lines changed

runtime/js-compute-runtime/host_interface/host_api.cpp

Lines changed: 124 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,129 @@ Result<std::optional<uint32_t>> AsyncHandle::select(const std::vector<AsyncHandl
101101
return res;
102102
}
103103

104+
namespace {
105+
106+
FastlySendError
107+
make_fastly_send_error(fastly_compute_at_edge_http_req_send_error_detail_t &send_error_detail) {
108+
FastlySendError res;
109+
110+
switch (send_error_detail.tag) {
111+
case 0: {
112+
res.tag = FastlySendError::detail::uninitialized;
113+
break;
114+
}
115+
case 1: {
116+
res.tag = FastlySendError::detail::ok;
117+
break;
118+
}
119+
case 2: {
120+
res.tag = FastlySendError::detail::dns_timeout;
121+
break;
122+
}
123+
case 3: {
124+
res.tag = FastlySendError::detail::dns_error;
125+
break;
126+
}
127+
case 4: {
128+
res.tag = FastlySendError::detail::destination_not_found;
129+
break;
130+
}
131+
case 5: {
132+
res.tag = FastlySendError::detail::destination_unavailable;
133+
break;
134+
}
135+
case 6: {
136+
res.tag = FastlySendError::detail::destination_ip_unroutable;
137+
break;
138+
}
139+
case 7: {
140+
res.tag = FastlySendError::detail::connection_refused;
141+
break;
142+
}
143+
case 8: {
144+
res.tag = FastlySendError::detail::connection_terminated;
145+
break;
146+
}
147+
case 9: {
148+
res.tag = FastlySendError::detail::connection_timeout;
149+
break;
150+
}
151+
case 10: {
152+
res.tag = FastlySendError::detail::connection_limit_reached;
153+
break;
154+
}
155+
case 11: {
156+
res.tag = FastlySendError::detail::tls_certificate_error;
157+
break;
158+
}
159+
case 12: {
160+
res.tag = FastlySendError::detail::tls_configuration_error;
161+
break;
162+
}
163+
case 13: {
164+
res.tag = FastlySendError::detail::http_incomplete_response;
165+
break;
166+
}
167+
case 14: {
168+
res.tag = FastlySendError::detail::http_response_header_section_too_large;
169+
break;
170+
}
171+
case 15: {
172+
res.tag = FastlySendError::detail::http_response_body_too_large;
173+
break;
174+
}
175+
case 16: {
176+
res.tag = FastlySendError::detail::http_response_timeout;
177+
break;
178+
}
179+
case 17: {
180+
res.tag = FastlySendError::detail::http_response_status_invalid;
181+
break;
182+
}
183+
case 18: {
184+
res.tag = FastlySendError::detail::http_upgrade_failed;
185+
break;
186+
}
187+
case 19: {
188+
res.tag = FastlySendError::detail::http_protocol_error;
189+
break;
190+
}
191+
case 20: {
192+
res.tag = FastlySendError::detail::http_request_cache_key_invalid;
193+
break;
194+
}
195+
case 21: {
196+
res.tag = FastlySendError::detail::http_request_uri_invalid;
197+
break;
198+
}
199+
case 22: {
200+
res.tag = FastlySendError::detail::internal_error;
201+
break;
202+
}
203+
case 23: {
204+
res.tag = FastlySendError::detail::tls_alert_received;
205+
break;
206+
}
207+
case 24: {
208+
res.tag = FastlySendError::detail::tls_protocol_error;
209+
break;
210+
}
211+
default: {
212+
// If we are here, this is either because the host does not provided send error details
213+
// Or a new error detail tag exists and we don't yet have it implemented
214+
res.tag = FastlySendError::detail::uninitialized;
215+
}
216+
}
217+
218+
res.dns_error_rcode = send_error_detail.dns_error_rcode;
219+
res.dns_error_info_code = send_error_detail.dns_error_info_code;
220+
res.tls_alert_id = send_error_detail.tls_alert_id;
221+
222+
return res;
223+
}
224+
225+
} // namespace
226+
104227
Result<HttpBody> HttpBody::make() {
105228
Result<HttpBody> res;
106229

@@ -300,7 +423,7 @@ Result<Response, FastlySendError> HttpPendingReq::wait() {
300423
fastly_compute_at_edge_http_req_error_t err;
301424
fastly_compute_at_edge_http_types_response_t ret;
302425
if (!fastly_compute_at_edge_http_req_pending_req_wait_v2(this->handle, &s, &ret, &err)) {
303-
res.emplace_err(FastlySendError(s));
426+
res.emplace_err(make_fastly_send_error(s));
304427
} else {
305428
res.emplace(make_response(ret));
306429
}

runtime/js-compute-runtime/host_interface/host_api.h

Lines changed: 1 addition & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
#include "core/allocator.h"
1515
#include "js/TypeDecls.h"
1616

17-
#include "host_interface/fastly.h"
18-
1917
#pragma clang diagnostic push
2018
#pragma clang diagnostic ignored "-Winvalid-offsetof"
2119
#include "js/Utility.h"
@@ -210,6 +208,7 @@ class AsyncHandle {
210208
};
211209

212210
class FastlySendError final {
211+
public:
213212
enum detail {
214213
/// The send-error-detail struct has not been populated.
215214
uninitialized,
@@ -275,126 +274,12 @@ class FastlySendError final {
275274
tls_protocol_error
276275
};
277276

278-
public:
279277
detail tag;
280278
uint16_t dns_error_rcode;
281279
uint16_t dns_error_info_code;
282280
uint8_t tls_alert_id;
283281

284282
const std::optional<std::string> message() const;
285-
286-
FastlySendError(fastly_compute_at_edge_http_req_send_error_detail_t send_error_detail) {
287-
switch (send_error_detail.tag) {
288-
case 0: {
289-
tag = detail::uninitialized;
290-
break;
291-
}
292-
case 1: {
293-
tag = detail::ok;
294-
break;
295-
}
296-
case 2: {
297-
tag = detail::dns_timeout;
298-
break;
299-
}
300-
case 3: {
301-
tag = detail::dns_error;
302-
break;
303-
}
304-
case 4: {
305-
tag = detail::destination_not_found;
306-
break;
307-
}
308-
case 5: {
309-
tag = detail::destination_unavailable;
310-
break;
311-
}
312-
case 6: {
313-
tag = detail::destination_ip_unroutable;
314-
break;
315-
}
316-
case 7: {
317-
tag = detail::connection_refused;
318-
break;
319-
}
320-
case 8: {
321-
tag = detail::connection_terminated;
322-
break;
323-
}
324-
case 9: {
325-
tag = detail::connection_timeout;
326-
break;
327-
}
328-
case 10: {
329-
tag = detail::connection_limit_reached;
330-
break;
331-
}
332-
case 11: {
333-
tag = detail::tls_certificate_error;
334-
break;
335-
}
336-
case 12: {
337-
tag = detail::tls_configuration_error;
338-
break;
339-
}
340-
case 13: {
341-
tag = detail::http_incomplete_response;
342-
break;
343-
}
344-
case 14: {
345-
tag = detail::http_response_header_section_too_large;
346-
break;
347-
}
348-
case 15: {
349-
tag = detail::http_response_body_too_large;
350-
break;
351-
}
352-
case 16: {
353-
tag = detail::http_response_timeout;
354-
break;
355-
}
356-
case 17: {
357-
tag = detail::http_response_status_invalid;
358-
break;
359-
}
360-
case 18: {
361-
tag = detail::http_upgrade_failed;
362-
break;
363-
}
364-
case 19: {
365-
tag = detail::http_protocol_error;
366-
break;
367-
}
368-
case 20: {
369-
tag = detail::http_request_cache_key_invalid;
370-
break;
371-
}
372-
case 21: {
373-
tag = detail::http_request_uri_invalid;
374-
break;
375-
}
376-
case 22: {
377-
tag = detail::internal_error;
378-
break;
379-
}
380-
case 23: {
381-
tag = detail::tls_alert_received;
382-
break;
383-
}
384-
case 24: {
385-
tag = detail::tls_protocol_error;
386-
break;
387-
}
388-
default: {
389-
// If we are here, this is either because the host does not provided send error details
390-
// Or a new error detail tag exists and we don't yet have it implemented
391-
tag = detail::uninitialized;
392-
}
393-
}
394-
dns_error_rcode = send_error_detail.dns_error_rcode;
395-
dns_error_info_code = send_error_detail.dns_error_info_code;
396-
tls_alert_id = send_error_detail.tls_alert_id;
397-
}
398283
};
399284

400285
/// A convenience wrapper for the host calls involving http bodies.

0 commit comments

Comments
 (0)