Hi everyone! 👋
I have an Appwrite Function running locally with Docker, but I’m struggling to debug it because execution doesn’t reach the breakpoints I set. I’d really appreciate any guidance on:
- How to debug Appwrite Functions locally
- Inspecting variables or stepping through code while running in Docker
Thanks so much in advance for any tips or best practices!
Personally the way I've been doing it is creating a mock context and simply executing the function's main file with the arguments you want. So for a Python function you have the main() function and it accepts context as an argument. Create a test file that calls the main file simulating the context object. Something like this:
class MockRequest:
def __init__(
self,
body_raw,
body,
headers,
scheme,
method,
url,
host,
port,
path,
query_string,
query,
):
self.body_raw = body_raw
self.body = body
self.headers = headers
self.scheme = scheme
self.method = method
self.url = url
self.host = host
self.port = port
self.path = path
self.query_string = query_string
self.query = query
class MockResponse:
def __init__(self):
self.response = None
def send(self, response):
self.response = response
print(f"Response: {response}")
def json(self, response):
self.response = response
return response
def empty(self):
return None
class MockContext:
def __init__(self, req: MockRequest):
self.req = req
self.res = MockResponse()
def log(self, message):
print(message)
def error(self, message):
print(f"ERROR: {message}")
I am already able to send request to my function but the execution doesn't come to the place where the break point is put. Thus, unable to know the state of a given variable. The only option currently available is to log it but logging it every place is tiresome and boring.
Well what I'm doing here is executing this through VSCode with breakpoints. I create a file that calls my appwrite functions main function by importing it:
from main import main # Your appwrite function entrypoint
def test():
req = MockRequest(
body_raw,
normalized_body,
headers,
scheme,
method_value,
url,
host,
port,
path_value,
query_string,
query,
)
context = MockContext(req)
main(context)
if __name__ == "__main__": # pragma: no cover
test()
Recommended threads
- Unable to push function from API KEY wit...
When trying to push functions from Gitlab CI (with an API KEY and using the CLI), i saw that i was unable to push functions. ``` $ appwrite client --endpoint $...
- Appwrite Functions not executing with a ...
I have multiple functions running with a CRON Job however, they all stopped executing around 35 mins ago from this post. Project ID:6a4a03920012bede992d Region:...
- Deployment fails at sidecar step "Build ...
Hi Appwrite team, I'm getting a consistent deployment failure on Appwrite Cloud. The build itself completes successfully, but a post-build sidecar step then fa...