Add --passstderr flag to forward STDERR through WebSocket#459
Open
Formatted wants to merge 1 commit into
Open
Conversation
…alnes#403) When --passstderr is enabled, STDERR output from the wrapped process is forwarded to WebSocket clients as tagged JSON messages: {"stream":"stderr","data":"error message"} STDOUT messages are also tagged for consistency: {"stream":"stdout","data":"output line"} This addresses the long-standing issue (joewalnes#403) where STDERR was silently swallowed, making it impossible for clients to see error output from their scripts (e.g., Perl warn, Python tracebacks). The output channel now closes only after both STDOUT and STDERR goroutines complete, ensuring no messages are lost. - Added PassStderr field to libwebsocketd.Config - Added passStderr parameter to NewProcessEndpoint - Added readStdoutTagged/readStderrTagged methods with sync.WaitGroup - Added tagMessage helper with proper JSON string escaping - Added 3 unit tests covering the new behavior - Updated --help text and README
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Adds a
--passstderrCLI flag that forwards STDERR output from the wrapped process to WebSocket clients as tagged JSON messages.Addresses: #403 (Feature Request: STDERR redirected through websockets, open since 2021)
Problem
Currently, STDERR output from subprocesses is silently swallowed — it's only logged on the server side and never reaches the WebSocket client. This makes debugging scripts nearly impossible, as
warn/diein Perl, Python tracebacks, and other error output is invisible to clients.Solution
When
--passstderris enabled:{"stream":"stderr","data":"error message"}{"stream":"stdout","data":"output line"}When
--passstderris not set (default), behavior is unchanged — STDERR is only logged server-side.Example
Client receives:
{"stream":"stdout","data":"normal output"} {"stream":"stderr","data":"warning: something went wrong"}Client-side usage
Changes
libwebsocketd/config.go— AddedPassStderrfield toConfiglibwebsocketd/process_endpoint.go— AddedpassStderrparameter toNewProcessEndpoint, newreadStdoutTagged/readStderrTaggedmethods withsync.WaitGroup, andtagMessagehelper with proper JSON escapinglibwebsocketd/handler.go— WirePassStderrconfig through toNewProcessEndpointconfig.go— Added--passstderrCLI flaghelp.go— Updated help textREADME.md— Mentioned new flag in features listCHANGES— Added changelog entrylibwebsocketd/process_endpoint_stderr_test.go— 3 unit tests covering the featureTesting
passStderrenabledpassStderrdisabled