-
Notifications
You must be signed in to change notification settings - Fork 960
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
Firebase Functions emulator stops with error when logging a string with an emoji on Windows #8002
Comments
This issue does not have all the information required by the template. Looks like you forgot to fill out some sections. Please update the issue with more information. |
Done! |
Thanks for creating a detailed report @lawther! Currently, I'm unable to reproduce this on a macOS machine, which makes me think that this issue might be specific to Windows. I'll try to get access to a Windows machine, or ask someone from our team to test this out. A couple of questions here - What version of the from firebase_functions import https_fn
@https_fn.on_request()
def on_request_example(req: https_fn.Request) -> https_fn.Response:
message = "🐦⬛ Blackbird"
return https_fn.Response("Hello world!" + message) |
Hi @aalej , Thanks for responding. In answer to your questions:
If I use your example, and visit http://localhost:5001/XXXXXX/us-central1/on_request_example, I correctly see "Hello world!🐦⬛ Blackbird" in the browser. However, if I change your sample code to add a log statement
Then I get 500 Internal Server Error: The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application. This is why I think the error is in the logging function. I originally encountered the problem when logging from a function, however I reduced it to the minimal repro I posted above. Here is the debug log:
|
Also, if I try simply using the log function outside the emulator with a simple test script:
I get the expected output
In the console I actually see the non-merged emoji of 🐦 followed by ⬛, but when pasting here it merges to 🐦⬛. But regardless, no error. |
Thanks for the additional information, and apologies for the delay. I got a Windows machine to test this on and was able to reproduce the error. I'll raise this to our engineering team and mark this as reproducible. Sharing the mcve here. |
Hey @lawther This looks like a character encoding issue. On macOS, terminals typically use To fix this, you can explicitly set the standard output encoding to UTF-8. Does the following work for you? from firebase_functions import https_fn
from firebase_functions import logger
import sys
# Set UTF-8 encoding
sys.stdout.reconfigure(encoding="utf-8")
@https_fn.on_request()
def on_request_example(req: https_fn.Request) -> https_fn.Response:
logger.info("🐦⬛ Blackbird")
return https_fn.Response("Ok") |
Hey @CorieW , Thanks for the reply. I'm away from my dev environment for the next few days, but I'll try your suggestion when I get back. In terms of Python and the Windows console, as you can see from an earlier comment of mine #8002 (comment) I can successfully use both the native Python print function and the Firebase logging functions from Python on Windows without starting the emulator. So I suspect the problem lies somewhere in how the emulator sets up the logging output on Windows. I haven't read enough of the code to know whether it's Python or Java that does the outputting once the emulator is started. |
I've confirmed that this issue doesn't occur when using JavaScript Firebase Functions. I'll have a look into Python Firebase Functions later this week to see if I can get it to automatically use UTF-8. For now, |
Nevermind, I looked into it today and figured out the issue. The problem was caused by character encoding defaulting to |
[REQUIRED] Environment info
firebase-tools:
PS C:\Users\github> firebase --version
13.27.0
Platform:
Windows 11
[REQUIRED] Test case
Put the following in main.py
In case it gets mangled, the UTF-8 of that string is
\xF0\x9F\x90\xA6\xE2\x80\x8D\xE2\xAC\x9B\x20\x42\x6C\x61\x63\x6B\x62\x69\x72\x64
[REQUIRED] Steps to reproduce
Now run the functions emulator with
firebase emulators:start --only functions
[REQUIRED] Expected behavior
The emulator starts up without error. If you remove the emoji from the message string, the emulator starts without error.
[REQUIRED] Actual behavior
An error is logged and the emulator doesn't correctly start
The text was updated successfully, but these errors were encountered: