Repository navigation
fix(functions): name the user's file in functions:serve errors - #300
Conversation
A function that threw while being loaded stopped functions:serve with
only the cause ("error: init"), and one broken file stopped the whole
server without saying which file to fix.
Wrap each function's build and load in FunctionLoadError, which names
the file relative to the project and keeps the original error as its
cause: "Could not load functions/api/boom.js: init".
#claude_code#
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
A function importing a package that was not installed printed a rollup warning with a long ../../ path, then failed with "Failed to resolve module specifier ... from data:text/javascript;base64,...", which names neither the user's file nor what to do. Turn rollup's UNRESOLVED_IMPORT warning into MissingPackageError: "Could not load functions/api/needs.js: functions/api/needs.js imports "not-installed-pkg", which is not installed. Run npm install in the project." Other rollup warnings still go to the default handler. The syntax-error test now also checks its "Could not load <file>:" prefix. #claude_code# 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
…e and line Functions were bundled and imported from a base64 data: URL, so a handler that threw at request time logged a stack trace pointing at data:text/javascript;base64,...:1:28 instead of the user's file. Write each bundle, with its source map, to a temporary .mjs file and import it by file URL, and enable Node's source-map support so the trace reads functions/broken.js:2:9. Jest maps stack traces on its own, so the test also checks that serve turns source maps on; checked against the built CLI, where the trace otherwise names the temporary bundle. #claude_code# 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
List the errors that now name the user's file: FunctionLoadError for a function that fails to bundle or load, MissingPackageError for a package that is not installed, and source-mapped stack traces from bundles loaded by file URL instead of a data: URL. Refresh the .talismanrc checksums for AGENTS.md and src/functions/cloud-functions.test.ts, whose flagged lines are prose and test names, not secrets. #claude_code# 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
- A missing package is refused only when a real file imports it
statically. A guarded dynamic import of an optional package is left
as a warning and serve starts, as before this branch.
- The importer is found through rollup's module graph, following the
commonjs plugin's virtual proxies, so a require() of a missing package
names the CommonJS function file instead of failing on the proxy's
null-byte id.
- A thrown non-error value keeps its text ("plain string", not
"undefined"), and a syntax error gives the file, line and column:
"Could not load functions/syn.js: Unexpected token ... (functions/syn.js:2:8)".
- The temporary bundle directory is removed once the functions are
loaded, whether loading succeeds or fails.
- Source maps are enabled once per serve, not once per function, and
leave the sources out of the inline maps.
- The two importer walks share one helper.
Refresh the .talismanrc checksum for src/functions/cloud-functions.test.ts
(flagged lines are test names, not secrets).
#claude_code#
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
🔒 Security Scan Results
⏱️ SLA Breach Summary
ℹ️ Vulnerabilities Without Available Fixes (Informational Only)The following vulnerabilities were detected but do not have fixes available (no upgrade or patch). These are excluded from failure thresholds:
✅ BUILD PASSED - All security checks passed |
rohan-agrawal-cs
left a comment
There was a problem hiding this comment.
Thanks, this is a clear improvement. Naming the file, the syntax-error location and the missing-package message all read well, and the guarded optional import() still serves. I checked it out, ran the cloud-functions suite, and ran the compiled CLI under plain Node to check the behavior outside Jest.
Should fix before merge
- Regression: prefix-only builtins (
node:sqlite,node:test,node:sea) are now refused as "not installed". They served on v2-dev. One-lineisBuiltinguard; see inline. - macOS: mapped stack-trace paths get an extra
/privateprefix because the temp dir isn't realpathed. One-line fix; see inline. Jest can't catch it.
Nits
- A load-time runtime throw doesn't get a location yet. The mapped frame is already in
cause.stack. sourceLocationshould not letrealpathSyncreplace the original error.- When the function file is the importer, the file name appears twice:
Could not load functions/api/needs.js: functions/api/needs.js imports "...". It would read better to drop the inner path when importer === function file. Optional.
(Review drafted with Claude Code; each finding above was reproduced locally.)
From the review of #300: - node:-only builtins (node:sqlite, node:test, node:sea) are not in builtinModules, so rollup reported them unresolved and serve refused them as missing packages. Skip anything isBuiltin() reports. - On macOS the temp directory sits under the /var -> /private/var symlink, and mapped stack frames came out as /private/Users/... Realpath the bundle directory so frames name the real source path. - A function that throws while loading gets the first stack frame inside the project as its location, as a syntax error does. - A failing realpath while finding that location no longer replaces the original error; the message falls back to "Could not load <file>:". - When the function file itself imports the missing package, the error is MissingPackageError on its own, without repeating the file name. Refresh the .talismanrc checksums for the changed files (flagged lines are test names and existing error wording, not secrets). #claude_code# 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
🔒 Security Scan Results
⏱️ SLA Breach Summary
ℹ️ Vulnerabilities Without Available Fixes (Informational Only)The following vulnerabilities were detected but do not have fixes available (no upgrade or patch). These are excluded from failure thresholds:
✅ BUILD PASSED - All security checks passed |
|
/ship 2b summary: @rohan-agrawal-cs, thanks for the review. Every point is addressed in 33a422a. I reproduced each one before changing it. Fixed:
Resolved: all 4 inline threads, each with a reply. Full suite is green (197 suites, 3,953 tests). Next step: needs an approval to merge. |
Merges #296 (env:update skips unchanged settings) and #300 (functions:serve names the user's file in its errors). The only conflict was .talismanrc: v2-dev's version is kept and the checksums of every file changed on either side are recomputed from the merged content. #claude_code# 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Finishes CL-8791 (V2 bug bash, scenario 9.1), item 3:
launch:functions:serveload and runtime errors did not name the user's file. Follows #299, which covered the rest of the ticket.What
Could not load functions/<file>.js: <cause>(FunctionLoadError). V1 printed only the cause (error: init), so with many functions you could not tell which file to fix.Could not load functions/syn.js: Unexpected token '='... (functions/syn.js:2:8).undefined.Could not load functions/api/needs.js: functions/api/needs.js imports "not-installed-pkg", which is not installed. Run npm install in the project.(MissingPackageError). This replaces a rollup warning with a long../../path followed by a base64data:URL error.require()from a CommonJS function is traced back through rollup's commonjs proxy to the function file.import()of an optional package still only warns, and serve starts as before.functions/<file>.js:<line>:<col>, notdata:text/javascript;base64,...:1:28. Each function is bundled with a source map into a temporary.mjsfile and imported by file URL. Serve turns on Node's source-map support once. The temporary directory is removed as soon as the functions are loaded, whether loading succeeds or fails.Notes for reviewers
loadDataURLkeeps its name although it now imports afile:URL. Renaming it would also churn its compiled-build test (test/integration/compiled-load-data-url.test.ts), which still passes.process.setSourceMapsEnabled(true). I checked the built CLI by hand. With the call, the trace readsfunctions/broken.js:2:9. Without it, the trace names the temporary bundle. It still maps correctly after the temporary files are deleted..talismanrcchecksums are refreshed for the files this branch changed. The flagged lines are prose, test names and existing error wording, not secrets. The refreshes sit in the last commit of their group, so earlier commits in this PR carry a stale checksum. The PR is squash-merged, so those in-between states never land.Tests
src/functions/cloud-functions.test.ts:npm test, 197 suites, 3,949 tests.#claude_code#
🤖 Generated with Claude Code