-
Notifications
You must be signed in to change notification settings - Fork 335
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Python workers: Better error handling when the handler is not defined (…
- Loading branch information
Showing
6 changed files
with
68 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
def test(): | ||
pass |
11 changes: 11 additions & 0 deletions
11
src/workerd/server/tests/python/undefined-handler/server.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { rejects } from 'node:assert'; | ||
|
||
export default { | ||
async test(ctrl, env) { | ||
await rejects(env.pythonWorker.fetch(new Request('http://example.com')), { | ||
name: 'Error', | ||
message: | ||
'Python entrypoint "undefined_handler.py" does not export a handler named "on_fetch"', | ||
}); | ||
}, | ||
}; |
37 changes: 37 additions & 0 deletions
37
src/workerd/server/tests/python/undefined-handler/undefined-handler.wd-test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using Workerd = import "/workerd/workerd.capnp"; | ||
|
||
const undefinedHandler :Workerd.Worker = ( | ||
modules = [ | ||
(name = "undefined_handler.py", pythonModule = embed "undefined_handler.py") | ||
], | ||
compatibilityDate = "2024-10-01", | ||
compatibilityFlags = [%PYTHON_FEATURE_FLAGS], | ||
); | ||
|
||
const server :Workerd.Worker = ( | ||
modules = [ | ||
(name = "server.js", esModule = embed "server.mjs") | ||
], | ||
bindings = [ | ||
( name = "pythonWorker", service = "undefinedHandler" ), | ||
], | ||
compatibilityDate = "2024-10-01", | ||
compatibilityFlags = ["nodejs_compat"], | ||
); | ||
|
||
|
||
const unitTests :Workerd.Config = ( | ||
services = [ | ||
( name = "external", | ||
network = ( | ||
tlsOptions = (trustBrowserCas = true) | ||
) | ||
), | ||
( name = "server", | ||
worker = .server | ||
), | ||
( name = "undefinedHandler", | ||
worker = .undefinedHandler | ||
), | ||
], | ||
); |
2 changes: 2 additions & 0 deletions
2
src/workerd/server/tests/python/undefined-handler/undefined_handler.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
def test(): | ||
pass |