Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: reflection issues with fetch #1279

Merged
merged 7 commits into from
Mar 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/cli/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,7 @@ val enabledFeatures = listOfNotNull(
"elide.tool.engine.MacLinkageFeature",
"elide.tool.feature.ToolingUmbrellaFeature",
"elide.runtime.feature.engine.NativeConsoleFeature",
"elide.runtime.feature.js.FetchFeature",
onlyIf(enablePython, "elide.runtime.feature.python.PythonFeature"),
onlyIf(enableNativeTransportV2, "elide.runtime.feature.engine.NativeTransportFeature"),
onlyIf(enableNativeCryptoV2, "elide.runtime.feature.engine.NativeCryptoFeature"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -905,15 +905,21 @@ private typealias ContextAccessor = () -> PolyglotContext
)

else -> displayFormattedError(
exc,
exc.message ?: "A runtime error was thrown",
exc.asHostException(),
exc.asHostException().message ?: "A runtime error was thrown",
advice = "This is an error in Elide. Please report this to the Elide Team with `elide bug`",
stacktrace = true,
internal = true,
)
}
}

// if this is a guest-side exception, throw it
exc.guestObject != null && exc.guestObject.isException -> {
logging.debug("Detected guest-side exception; throwing")
exc.guestObject.throwException()
}

exc.isGuestException -> displayFormattedError(
exc,
exc.message ?: "An error was thrown",
Expand All @@ -931,6 +937,8 @@ private typealias ContextAccessor = () -> PolyglotContext
exc.message ?: "An error was thrown",
internal = true,
)

else -> error("Unhandled polyglot error type: $exc")
}
// in interactive sessions, return `null` if the error is non-fatal; this tells the outer execution loop to ignore
// the exception (since it has been printed to the user), and continue with the interactive session.
Expand Down Expand Up @@ -1229,10 +1237,37 @@ private typealias ContextAccessor = () -> PolyglotContext
parsed.execute()

} catch (exc: PolyglotException) {
logging.debug("Caught polyglot exception: $exc")
if (logging.isEnabled(LogLevel.DEBUG)) {
logging.debug(StringBuilder().apply {
append("Error Info: ")
append("message{${exc.message}} ")
append("source{${exc.sourceLocation}} ")
append("isGuestException{${exc.isGuestException}} ")
append("isHostException{${exc.isHostException}} ")
append("isCancelled{${exc.isCancelled}} ")
append("isInterrupted{${exc.isInterrupted}} ")
append("isResourceExhausted{${exc.isResourceExhausted}} ")
append("isSyntaxError{${exc.isSyntaxError}} ")
append("isIncompleteSource{${exc.isIncompleteSource}} ")
append("isInternalError{${exc.isInternalError}} ")
append("cause{${exc.cause}}")
val guestObj = exc.guestObject
if (guestObj != null) {
append(" // Guest Object: ")
append("isHostObject{${guestObj.isHostObject}} ")
append("isNull{${guestObj.isNull}} ")
append("isException{${guestObj.isException}} ")
append("isString{${guestObj.isString}}")
}
}.toString())
}
when (val throwable = processUserCodeError(primaryLanguage, exc)) {
null -> {}
else -> throw throwable
}
} catch (exc: Throwable) {
logging.debug("Caught (and re-throwing) exception: $exc")
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,303 @@
{
"reflection": [
{
"type": "java.util.Optional",
"methods": [
{
"name": "get"
},
{
"name": "isPresent"
}
]
},
{
"type": "jdk.internal.net.http.HttpResponseImpl",
"methods": [
{
"name": "statusCode"
},
{
"name": "headers"
},
{
"name": "body"
}
]
},
{
"type": "java.net.http.HttpHeaders",
"methods": [
{
"name": "firstValue"
},
{
"name": "allValues"
},
{
"name": "map"
}
]
},
{
"type": "jdk.internal.net.http.HttpClientFacade",
"methods": [
{
"name": "send"
}
]
},
{
"type": "java.net.http.HttpClient",
"methods": [
{
"name": "send"
}
]
},
{
"type": "jdk.internal.net.http.HttpClientBuilderImpl"
},
{
"type": "jdk.internal.net.http.HttpRequestBuilderImpl"
},
{
"type": "java.lang.constant.Constable"
},
{
"type": "java.lang.Throwable",
"methods": [
{
"name": "toString"
}
]
},
{
"type": "java.lang.AutoCloseable"
},
{
"type": "java.net.URI",
"methods": [
{
"name": "<init>",
"parameterTypes": [
"java.lang.String"
]
},
{
"name": "isAbsolute"
},
{
"name": "resolve"
},
{
"name": "getUserInfo"
},
{
"name": "getScheme"
},
{
"name": "getFragment"
},
{
"name": "getSchemeSpecificPart"
},
{
"name": "toString"
},
{
"name": "getHost"
}
]
},
{
"type": "org.graalvm.nativeimage.MissingReflectionRegistrationError"
},
{
"type": "java.io.Serializable"
},
{
"type": "java.lang.Comparable"
},
{
"type": "java.net.http.HttpClient",
"methods": [
{
"name": "newBuilder"
}
]
},
{
"type": "java.net.http.HttpClient$Builder",
"methods": [
{
"name": "followRedirects"
},
{
"name": "build"
}
]
},
{
"type": "java.net.http.HttpClient.Redirect"
},
{
"type": "java.net.http.HttpClient$Redirect"
},
{
"type": "java.net.http.HttpRequest",
"methods": [
{
"name": "newBuilder"
},
{
"name": "uri"
},
{
"name": "method"
},
{
"name": "bodyPublisher"
},
{
"name": "headers"
}
]
},
{
"type": "java.net.http.HttpRequest.Builder",
"methods": [
{
"name": "setHeader"
},
{
"name": "header"
},
{
"name": "headers"
},
{
"name": "method"
},
{
"name": "build"
}
]
},
{
"type": "java.net.http.HttpRequest$Builder",
"methods": [
{
"name": "setHeader"
},
{
"name": "header"
},
{
"name": "headers"
},
{
"name": "method"
},
{
"name": "build"
}
]
},
{
"type": "java.net.http.HttpRequest.BodyPublishers",
"methods": [
{
"name": "ofString"
},
{
"name": "ofByteArray"
},
{
"name": "ofInputStream"
},
{
"name": "ofFile"
},
{
"name": "ofNone"
}
]
},
{
"type": "java.net.http.HttpRequest$BodyPublishers",
"methods": [
{
"name": "ofString"
},
{
"name": "ofByteArray"
},
{
"name": "ofInputStream"
},
{
"name": "ofFile"
},
{
"name": "noBody"
}
]
},
{
"type": "java.net.http.HttpResponse",
"methods": [
{
"name": "statusCode"
},
{
"name": "headers"
},
{
"name": "body"
}
]
},
{
"type": "java.net.http.HttpResponse.BodyHandlers",
"methods": [
{
"name": "ofString"
},
{
"name": "ofByteArray"
},
{
"name": "ofInputStream"
},
{
"name": "ofFile"
},
{
"name": "ofDiscard"
}
]
},
{
"type": "java.net.http.HttpResponse$BodyHandlers",
"methods": [
{
"name": "ofString"
},
{
"name": "ofByteArray"
},
{
"name": "ofInputStream"
},
{
"name": "ofFile"
}
]
},
{
"type": "java.util.Base64"
},
{
"type": "sun.util.logging.resources.logging",
"methods": [
Expand Down Expand Up @@ -2917,6 +3215,9 @@
}
],
"resources": [
{
"glob": "META-INF/services/java.net.spi.InetAddressResolverProvider"
},
{
"glob": "org/jline/utils/*.caps"
},
Expand Down
Loading
Loading