Skip to content

Commit

Permalink
Move workerd/api/util.c++ to KJ_IF_SOME
Browse files Browse the repository at this point in the history
Bug: EW-7618
Test: bazel test //...
  • Loading branch information
ohodson committed Sep 23, 2023
1 parent 1495115 commit 2e0ee4f
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/workerd/api/util.c++
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ void parseQueryString(kj::Vector<kj::Url::QueryParam>& query, kj::ArrayPtr<const

kj::Maybe<kj::String> readContentTypeParameter(kj::StringPtr contentType,
kj::StringPtr param) {
KJ_IF_MAYBE(parsed, MimeType::tryParse(contentType)) {
return parsed->params().find(toLower(param)).map([](auto& value) {
KJ_IF_SOME(parsed, MimeType::tryParse(contentType)) {
return parsed.params().find(toLower(param)).map([](auto& value) {
return kj::str(value);
});
}
return nullptr;
return kj::none;
}

kj::Maybe<kj::Exception> translateKjException(const kj::Exception& exception,
Expand All @@ -87,7 +87,7 @@ kj::Maybe<kj::Exception> translateKjException(const kj::Exception& exception,
}
}

return nullptr;
return kj::none;
}

namespace {
Expand All @@ -98,15 +98,15 @@ auto translateTeeErrors(Func&& f) -> decltype(kj::fwd<Func>(f)()) {
co_return co_await f();
} catch (...) {
auto exception = kj::getCaughtExceptionAsKj();
KJ_IF_MAYBE(e, translateKjException(exception, {
KJ_IF_SOME(e, translateKjException(exception, {
{ "tee buffer size limit exceeded"_kj,
"ReadableStream.tee() buffer limit exceeded. This error usually occurs when a Request or "
"Response with a large body is cloned, then only one of the clones is read, forcing "
"the Workers runtime to buffer the entire body in memory. To fix this issue, remove "
"unnecessary calls to Request/Response.clone() and ReadableStream.tee(), and always read "
"clones/tees in parallel."_kj },
})) {
kj::throwFatalException(kj::mv(*e));
kj::throwFatalException(kj::mv(e));
}
kj::throwFatalException(kj::mv(exception));
}
Expand Down Expand Up @@ -219,10 +219,10 @@ double dateNow() {
kj::Maybe<jsg::V8Ref<v8::Object>> cloneRequestCf(
jsg::Lock& js,
kj::Maybe<jsg::V8Ref<v8::Object>> maybeCf) {
KJ_IF_MAYBE(cf, maybeCf) {
return cf->deepClone(js);
KJ_IF_SOME(cf, maybeCf) {
return cf.deepClone(js);
}
return nullptr;
return kj::none;
}

void maybeWarnIfNotText(kj::StringPtr str) {
Expand Down

0 comments on commit 2e0ee4f

Please sign in to comment.