Skip to content

Firebase Functions emulator stops with error when logging a string with an emoji on Windows #226

Closed
@lawther

Description

@lawther

[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

from firebase_functions import logger

message = "🐦‍⬛ Blackbird"
logger.log(message)

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

[debug] [2024-11-28T03:29:24.546Z] ----------------------------------------------------------------------
[debug] [2024-11-28T03:29:24.549Z] Command:       C:\Program Files\nodejs\node.exe C:\Users\XXXXXX\AppData\Roaming\npm\node_modules\firebase-tools\lib\bin\firebase.js emulators:start --only functions --debug
[debug] [2024-11-28T03:29:24.549Z] CLI Version:   13.27.0
[debug] [2024-11-28T03:29:24.550Z] Platform:      win32
[debug] [2024-11-28T03:29:24.550Z] Node Version:  v20.12.2
[debug] [2024-11-28T03:29:24.550Z] Time:          Thu Nov 28 2024 14:29:24 GMT+1100 (Australian Eastern Daylight Time)
[debug] [2024-11-28T03:29:24.550Z] ----------------------------------------------------------------------
[debug] 
[debug] [2024-11-28T03:29:24.690Z] Object "" in "firebase.json" has unknown property: {"additionalProperty":"flutter"}
[debug] [2024-11-28T03:29:24.698Z] > command requires scopes: ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","https://www.googleapis.com/auth/cloud-platform"]
[debug] [2024-11-28T03:29:24.699Z] > authorizing via signed-in user (XXXXXXX@gmail.com)
[info] i  emulators: Starting emulators: functions {"metadata":{"emulator":{"name":"hub"},"message":"Starting emulators: functions"}}
[debug] [2024-11-28T03:29:24.707Z] [logging] Logging Emulator only supports listening on one address (127.0.0.1). Not listening on ::1
[debug] [2024-11-28T03:29:24.707Z] assigned listening specs for emulators {"user":{"hub":[{"address":"127.0.0.1","family":"IPv4","port":4400},{"address":"::1","family":"IPv6","port":4400}],"ui":[{"address":"127.0.0.1","family":"IPv4","port":4000},{"address":"::1","family":"IPv6","port":4000}],"logging":[{"address":"127.0.0.1","family":"IPv4","port":4500}]},"metadata":{"message":"assigned listening specs for emulators"}}
[debug] [2024-11-28T03:29:24.713Z] [hub] writing locator at C:\Users\XXXXXX\AppData\Local\Temp\hub-XXXXXX.json
[debug] [2024-11-28T03:29:24.734Z] Checked if tokens are valid: true, expires at: 1732766630140
[debug] [2024-11-28T03:29:24.734Z] Checked if tokens are valid: true, expires at: 1732766630140
[debug] [2024-11-28T03:29:24.736Z] >>> [apiv2][query] GET https://firebase.googleapis.com/v1beta1/projects/XXXXXX [none]
[debug] [2024-11-28T03:29:25.276Z] <<< [apiv2][status] GET https://firebase.googleapis.com/v1beta1/projects/XXXXXX 200
[debug] [2024-11-28T03:29:25.276Z] <<< [apiv2][body] GET https://firebase.googleapis.com/v1beta1/projects/XXXXXX {"projectId":"XXXXXX","projectNumber":"751502879957","displayName":"XXXXXX","name":"projects/XXXXXX","resources":{"hostingSite":"XXXXXX"},"state":"ACTIVE","etag":"XXXXXX"}
[debug] [2024-11-28T03:29:25.281Z] [functions] Functions Emulator only supports listening on one address (127.0.0.1). Not listening on ::1
[debug] [2024-11-28T03:29:25.282Z] [eventarc] Eventarc Emulator only supports listening on one address (127.0.0.1). Not listening on ::1
[debug] [2024-11-28T03:29:25.282Z] [tasks] Cloud Tasks Emulator only supports listening on one address (127.0.0.1). Not listening on ::1
[debug] [2024-11-28T03:29:25.282Z] late-assigned ports for functions and eventarc emulators {"user":{"hub":[{"address":"127.0.0.1","family":"IPv4","port":4400},{"address":"::1","family":"IPv6","port":4400}],"ui":[{"address":"127.0.0.1","family":"IPv4","port":4000},{"address":"::1","family":"IPv6","port":4000}],"logging":[{"address":"127.0.0.1","family":"IPv4","port":4500}],"functions":[{"address":"127.0.0.1","family":"IPv4","port":5001}],"eventarc":[{"address":"127.0.0.1","family":"IPv4","port":9299}],"tasks":[{"address":"127.0.0.1","family":"IPv4","port":9499}]},"metadata":{"message":"late-assigned ports for functions and eventarc emulators"}}
[warn] !  functions: The following emulators are not running, calls to these services from the Functions emulator will affect production: apphosting, auth, firestore, database, hosting, pubsub, storage, dataconnect {"metadata":{"emulator":{"name":"functions"},"message":"The following emulators are not running, calls to these services from the Functions emulator will affect production: \u001b[1mapphosting, auth, firestore, database, hosting, pubsub, storage, dataconnect\u001b[22m"}}
[debug] [2024-11-28T03:29:25.286Z] defaultcredentials: writing to file C:\Users\XXXXXX\AppData\Roaming\firebase\XXXXXX_gmail.com_application_default_credentials.json
[debug] [2024-11-28T03:29:25.287Z] Setting GAC to C:\Users\XXXXXX\AppData\Roaming\firebase\XXXXXX_gmail.com_application_default_credentials.json {"metadata":{"emulator":{"name":"functions"},"message":"Setting GAC to C:\\Users\\XXXXXX\\AppData\\Roaming\\firebase\\XXXXXX_gmail.com_application_default_credentials.json"}}
[debug] [2024-11-28T03:29:25.288Z] Checked if tokens are valid: true, expires at: 1732766630140
[debug] [2024-11-28T03:29:25.288Z] Checked if tokens are valid: true, expires at: 1732766630140
[debug] [2024-11-28T03:29:25.289Z] >>> [apiv2][query] GET https://firebase.googleapis.com/v1beta1/projects/XXXXXX/adminSdkConfig [none]
[debug] [2024-11-28T03:29:25.666Z] <<< [apiv2][status] GET https://firebase.googleapis.com/v1beta1/projects/XXXXXX/adminSdkConfig 200
[debug] [2024-11-28T03:29:25.667Z] <<< [apiv2][body] GET https://firebase.googleapis.com/v1beta1/projects/XXXXXX/adminSdkConfig {"projectId":"XXXXXX","storageBucket":"XXXXXX.firebasestorage.app"}
[info] i  functions: Watching "C:\Users\XXXXXX\github\XXXXXX\functions" for Cloud Functions... {"metadata":{"emulator":{"name":"functions"},"message":"Watching \"C:\\Users\\XXXXXX\\github\\XXXXXX\\functions\" for Cloud Functions..."}}
[debug] [2024-11-28T03:29:25.703Z] Customer code is not Node
[debug] [2024-11-28T03:29:25.704Z] Validating python source
[debug] [2024-11-28T03:29:25.704Z] Building python source
[info] i  functions: Loaded environment variables from .env. 
[debug] [2024-11-28T03:29:25.707Z] Could not find functions.yaml. Must use http discovery
[debug] [2024-11-28T03:29:25.718Z] Running command with virtualenv: command="C:\Users\XXXXXX\github\XXXXXX\functions\venv\Scripts\activate.bat", args=["","&&","python.exe","-c","\"import firebase_functions; import os; print(os.path.dirname(firebase_functions.__file__))\""]
[debug] [2024-11-28T03:29:25.812Z] stdout: C:\Users\XXXXXX\github\XXXXXX\functions\venv\Lib\site-packages\firebase_functions

[debug] [2024-11-28T03:29:25.818Z] Running admin server with args: ["python.exe","\"C:\\Users\\XXXXXX\\github\\XXXXXX\\functions\\venv\\Lib\\site-packages\\firebase_functions\\private\\serving.py\""] and env: {"GCLOUD_PROJECT":"XXXXXX","K_REVISION":"1","PORT":"80","GOOGLE_CLOUD_QUOTA_PROJECT":"XXXXXX","FUNCTIONS_EMULATOR":"true","TZ":"UTC","FIREBASE_DEBUG_MODE":"true","FIREBASE_DEBUG_FEATURES":"{\"skipTokenVerification\":true,\"enableCors\":true}","FIREBASE_EMULATOR_HUB":"127.0.0.1:4400","CLOUD_EVENTARC_EMULATOR_HOST":"http://127.0.0.1:9299","CLOUD_TASKS_EMULATOR_HOST":"127.0.0.1:9499","FIREBASE_CONFIG":"{\"storageBucket\":\"XXXXXX.firebasestorage.app\",\"projectId\":\"XXXXXX\"}","GOOGLE_APPLICATION_CREDENTIALS":"C:\\Users\\XXXXXX\\AppData\\Roaming\\firebase\\XXXXXX_gmail.com_application_default_credentials.json","ADMIN_PORT":"8081"} in C:\Users\XXXXXX\github\XXXXXX\functions
[debug] [2024-11-28T03:29:25.819Z] Running command with virtualenv: command="C:\Users\XXXXXX\github\XXXXXX\functions\venv\Scripts\activate.bat", args=["","&&","python.exe","\"C:\\Users\\XXXXXX\\github\\XXXXXX\\functions\\venv\\Lib\\site-packages\\firebase_functions\\private\\serving.py\""]
[info]  * Serving Flask app 'serving'
 * Debug mode: off

[error] WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
 * Running on http://127.0.0.1:8081

[error] Press CTRL+C to quit

[error] [2024-11-28 03:29:27,230] ERROR in app: Exception on /__/functions.yaml [GET]
Traceback (most recent call last):
  File "C:\Users\XXXXXX\github\XXXXXX\functions\venv\Lib\site-packages\flask\app.py", line 1473, in wsgi_app
    response = self.full_dispatch_request()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\XXXXXX\github\XXXXXX\functions\venv\Lib\site-packages\flask\app.py", line 882, in full_dispatch_request
    rv = self.handle_user_exception(e)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\XXXXXX\github\XXXXXX\functions\venv\Lib\site-packages\flask\app.py", line 880, in full_dispatch_request
    rv = self.dispatch_request()
         ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\XXXXXX\github\XXXXXX\functions\venv\Lib\site-packages\flask\app.py", line 865, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\XXXXXX\github\XXXXXX\functions\venv\Lib\site-packages\firebase_functions\private\serving.py", line 122, in get_functions_yaml
    functions = get_functions()
                ^^^^^^^^^^^^^^^
  File "C:\Users\XXXXXX\github\XXXXXX\functions\venv\Lib\site-packages\firebase_functions\private\serving.py", line 40, in get_functions
    spec.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 995, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "C:\Users\XXXXXX\github\XXXXXX\functions\main.py", line 4, in <module>
    logger.log(message)
  File "C:\Users\XXXXXX\github\XXXXXX\functions\venv\Lib\site-packages\firebase_functions\logger.py", line 112, in log
    write(_entry_from_args(LogSeverity.NOTICE, *args, **kwargs))
  File "C:\Users\XXXXXX\github\XXXXXX\functions\venv\Lib\site-packages\firebase_functions\logger.py", line 97, in write
    print(_json.dumps(_remove_circular(entry), ensure_ascii=False),
  File "C:\Users\XXXXXX\AppData\Local\Programs\Python\Python312\Lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeEncodeError: 'charmap' codec can't encode characters in position 35-37: character maps to <undefined>

[debug] [2024-11-28T03:29:27.234Z] Got response code 500; body <!doctype html>
<html lang=en>
<title>500 Internal Server Error</title>
<h1>Internal Server Error</h1>
<p>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.</p>

[error] 127.0.0.1 - - [28/Nov/2024 03:29:27] "GET /__/functions.yaml HTTP/1.1" 500 -

[error] 127.0.0.1 - - [28/Nov/2024 03:29:27] "GET /__/quitquitquit HTTP/1.1" 200 -

[error] !!  functions: Failed to load function definition from source: FirebaseError: Functions codebase could not be analyzed successfully. It may have a syntax or runtime error {"metadata":{"emulator":{"name":"functions"},"message":"Failed to load function definition from source: FirebaseError: Functions codebase could not be analyzed successfully. It may have a syntax or runtime error"}}
[debug] [2024-11-28T03:29:27.256Z] Could not find VSCode notification endpoint: FetchError: request to http://localhost:40001/vscode/notify failed, reason: . If you are not running the Firebase Data Connect VSCode extension, this is expected and not an issue.
[info] 
┌─────────────────────────────────────────────────────────────┐
│ ✔  All emulators ready! It is now safe to connect your app. │
│ i  View Emulator UI at http://127.0.0.1:4000/               │
└─────────────────────────────────────────────────────────────┘

┌───────────┬────────────────┬─────────────────────────────────┐
│ Emulator  │ Host:Port      │ View in Emulator UI             │
├───────────┼────────────────┼─────────────────────────────────┤
│ Functions │ 127.0.0.1:5001 │ http://127.0.0.1:4000/functions │
└───────────┴────────────────┴─────────────────────────────────┘
  Emulator Hub running at 127.0.0.1:4400
  Other reserved ports: 4500

Issues? Report them at https://github.com/firebase/firebase-tools/issues and attach the *-debug.log files.
 
[debug] [2024-11-28T03:29:30.968Z] Received signal SIGINT (Ctrl-C) 1
[info]  
[info] i  emulators: Received SIGINT (Ctrl-C) for the first time. Starting a clean shutdown. 
[info] i  emulators: Please wait for a clean shutdown or send the SIGINT (Ctrl-C) signal again to stop right now. 
[info] i  emulators: Shutting down emulators. {"metadata":{"emulator":{"name":"hub"},"message":"Shutting down emulators."}}
[info] i  ui: Stopping Emulator UI {"metadata":{"emulator":{"name":"ui"},"message":"Stopping Emulator UI"}}
[info] i  functions: Stopping Functions Emulator {"metadata":{"emulator":{"name":"functions"},"message":"Stopping Functions Emulator"}}
[info] i  eventarc: Stopping Eventarc Emulator {"metadata":{"emulator":{"name":"eventarc"},"message":"Stopping Eventarc Emulator"}}
[info] i  tasks: Stopping Cloud Tasks Emulator {"metadata":{"emulator":{"name":"tasks"},"message":"Stopping Cloud Tasks Emulator"}}
[info] i  hub: Stopping emulator hub {"metadata":{"emulator":{"name":"hub"},"message":"Stopping emulator hub"}}
[info] i  logging: Stopping Logging Emulator {"metadata":{"emulator":{"name":"logging"},"message":"Stopping Logging Emulator"}}
[debug] [2024-11-28T03:29:30.980Z] Could not find VSCode notification endpoint: FetchError: request to http://localhost:40001/vscode/notify failed, reason: . If you are not running the Firebase Data Connect VSCode extension, this is expected and not an issue.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions