-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix(emulator): stringify send() errors before writing them to stderr #10905
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
Merged
joehan
merged 6 commits into
firebase:main
from
mattsears18:fix/emulator-log-flush-stringify-err
Sep 1, 2026
+84
−5
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4f1c712
fix(emulator): stringify send() errors before writing them to stderr
mattsears18 8b6112b
Update src/emulator/types.ts
mattsears18 c887517
fix(emulator): restore the send() call and drop the unneeded any cast
mattsears18 b2b2f76
Merge branch 'main' into fix/emulator-log-flush-stringify-err
joehan 0a0ecc2
Merge branch 'main' into fix/emulator-log-flush-stringify-err
joehan 51608ed
Merge branch 'main' into fix/emulator-log-flush-stringify-err
joehan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| - Fixed an issue where the Functions emulator replaced an IPC failure with an unrelated `TypeError` about stream chunk types, hiding why the runtime became unreachable (#10876). | ||
| - [Added] Add -f, --force option to `firebase ext:migrate`. | ||
| - [Fixed] Fix parameter type preservation and optional system parameter handling during extension updates in `firebase ext:migrate`. | ||
| - [Fixed] Fix parameter type preservation and optional system parameter handling during extension updates in `firebase ext:migrate` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| import { expect } from "chai"; | ||
| import * as sinon from "sinon"; | ||
|
|
||
| import { EmulatorLog } from "./types"; | ||
|
|
||
| type SendCallback = (err: unknown) => void; | ||
|
|
||
| describe("EmulatorLog", () => { | ||
| describe("flush()", () => { | ||
| let stderrWrite: sinon.SinonStub; | ||
| // eslint-disable-next-line @typescript-eslint/unbound-method | ||
| const originalSend = process.send; | ||
|
|
||
| beforeEach(() => { | ||
| // Enforce the same chunk types the real stream does, so a regression throws here too. | ||
| stderrWrite = sinon.stub(process.stderr, "write").callsFake((chunk: unknown): boolean => { | ||
| if (typeof chunk !== "string" && !ArrayBuffer.isView(chunk)) { | ||
| throw new TypeError( | ||
| `The "chunk" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received ${typeof chunk}`, | ||
| ); | ||
| } | ||
| return true; | ||
| }); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| sinon.restore(); | ||
| process.send = originalSend; | ||
| }); | ||
|
|
||
| // Reports `err` to the send callback, the way Node does when the IPC channel has failed. | ||
| function stubSend(err: unknown): void { | ||
| process.send = (( | ||
| _message: unknown, | ||
| _sendHandle: unknown, | ||
| _options: unknown, | ||
| callback: SendCallback, | ||
| ): boolean => { | ||
| callback(err); | ||
| return true; | ||
| }) as unknown as typeof process.send; | ||
| } | ||
|
|
||
| it("writes the stack of an Error reported by process.send()", () => { | ||
| stubSend(new Error("channel closed")); | ||
|
|
||
| expect(() => new EmulatorLog("INFO", "system", "hello").log()).to.not.throw(); | ||
|
|
||
| expect(stderrWrite.calledOnce).to.be.true; | ||
| const written = stderrWrite.firstCall.args[0] as string; | ||
| expect(written).to.be.a("string"); | ||
| expect(written).to.contain("channel closed"); | ||
| expect(written).to.match(/\n$/); | ||
| }); | ||
|
|
||
| it("writes a non-Error reported by process.send()", () => { | ||
| stubSend("ERR_IPC_CHANNEL_CLOSED"); | ||
|
|
||
| expect(() => new EmulatorLog("INFO", "system", "hello").log()).to.not.throw(); | ||
|
|
||
| expect(stderrWrite.calledOnce).to.be.true; | ||
| expect(stderrWrite.firstCall.args[0]).to.contain("ERR_IPC_CHANNEL_CLOSED"); | ||
| }); | ||
|
|
||
| it("writes nothing when process.send() succeeds", () => { | ||
| stubSend(null); | ||
|
|
||
| new EmulatorLog("INFO", "system", "hello").log(); | ||
|
|
||
| expect(stderrWrite.called).to.be.false; | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.