@vercel/python 6.0.1 → 6.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/vc_init.py +25 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/python",
3
- "version": "6.0.1",
3
+ "version": "6.0.2",
4
4
  "main": "./dist/index.js",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://vercel.com/docs/runtimes#official-runtimes/python",
@@ -21,7 +21,7 @@
21
21
  "@types/jest": "27.4.1",
22
22
  "@types/node": "14.18.33",
23
23
  "@types/which": "3.0.0",
24
- "@vercel/build-utils": "12.2.4",
24
+ "@vercel/build-utils": "13.0.0",
25
25
  "cross-env": "7.0.3",
26
26
  "execa": "^1.0.0",
27
27
  "fs-extra": "11.1.1",
package/vc_init.py CHANGED
@@ -9,6 +9,7 @@ import inspect
9
9
  import asyncio
10
10
  import http
11
11
  import time
12
+ import traceback
12
13
  from importlib import util
13
14
  from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
14
15
  import socket
@@ -51,6 +52,20 @@ def setup_logging(send_message: Callable[[dict], None], storage: contextvars.Con
51
52
  except Exception:
52
53
  message = repr(getattr(record, "msg", ""))
53
54
 
55
+ with contextlib.suppress(Exception):
56
+ if record.exc_info:
57
+ # logging allows exc_info=True or a (type, value, tb) tuple
58
+ exc_info = record.exc_info
59
+ if exc_info is True:
60
+ exc_info = sys.exc_info()
61
+ if isinstance(exc_info, tuple):
62
+ tb = ''.join(traceback.format_exception(*exc_info))
63
+ if tb:
64
+ if message:
65
+ message = f"{message}\n{tb}"
66
+ else:
67
+ message = tb
68
+
54
69
  if record.levelno >= logging.CRITICAL:
55
70
  level = "fatal"
56
71
  elif record.levelno >= logging.ERROR:
@@ -143,6 +158,12 @@ def setup_logging(send_message: Callable[[dict], None], storage: contextvars.Con
143
158
  builtins.print = print_wrapper(builtins.print)
144
159
 
145
160
 
161
+ def _stderr(message: str):
162
+ with contextlib.suppress(Exception):
163
+ _original_stderr.write(message + "\n")
164
+ _original_stderr.flush()
165
+
166
+
146
167
  # If running in the platform (IPC present), logging must be setup before importing user code so that
147
168
  # logs happening outside the request context are emitted correctly.
148
169
  ipc_sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
@@ -321,8 +342,8 @@ if 'VERCEL_IPC_PATH' in os.environ:
321
342
  if 'handler' in __vc_variables or 'Handler' in __vc_variables:
322
343
  base = __vc_module.handler if ('handler' in __vc_variables) else __vc_module.Handler
323
344
  if not issubclass(base, BaseHTTPRequestHandler):
324
- print('Handler must inherit from BaseHTTPRequestHandler')
325
- print('See the docs: https://vercel.com/docs/functions/serverless-functions/runtimes/python')
345
+ _stderr('Handler must inherit from BaseHTTPRequestHandler')
346
+ _stderr('See the docs: https://vercel.com/docs/functions/serverless-functions/runtimes/python')
326
347
  exit(1)
327
348
 
328
349
  class Handler(BaseHandler, base):
@@ -494,8 +515,8 @@ if 'VERCEL_IPC_PATH' in os.environ:
494
515
  _init_log_buf.clear()
495
516
  server.serve_forever()
496
517
 
497
- print('Missing variable `handler` or `app` in file "__VC_HANDLER_ENTRYPOINT".')
498
- print('See the docs: https://vercel.com/docs/functions/serverless-functions/runtimes/python')
518
+ _stderr('Missing variable `handler` or `app` in file "__VC_HANDLER_ENTRYPOINT".')
519
+ _stderr('See the docs: https://vercel.com/docs/functions/serverless-functions/runtimes/python')
499
520
  exit(1)
500
521
 
501
522
  if 'handler' in __vc_variables or 'Handler' in __vc_variables: