fix: exit non-zero when CLI flag/env parsing fails - #1714
Open
stareezy-1 wants to merge 1 commit into
Open
Conversation
Flag and env-var parse errors (e.g. an invalid TUNNEL_GRACE_PERIOD) are returned by urfave/cli's app.Run without being printed, and runApp discarded the error, so cloudflared exited 0 with no output. Print the error to stderr and exit 1 so scripts and service managers can detect the failure.
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
cloudflaredexits with status 0 and no output when a flag or environmentvariable fails to parse, e.g.
TUNNEL_GRACE_PERIOD=10(see #1606).Problem
TUNNEL_GRACE_PERIOD=10(missing the duration unit) failstime.ParseDurationinside urfave/cli's flag setup.App.Runreturns thaterror without printing anything, and all four
runAppimplementationsdiscarded the returned error:
so the process exited 0 silently. The same discard made the CLI case
(
cloudflared tunnel --grace-period 10 run) exit 0 after printing"Incorrect Usage", which breaks scripts and service managers that rely on
the exit status. The issue also reports
systemdreporting a confusing"protocol" failure.
Fix
runAppAndExithelper (cmd/cloudflared/run_app.go): runs the app,prints any returned error to stderr, and exits 1.
runAppimplementations (generic/linux/macos/windows) now useit instead of discarding the error.
Behavior before → after:
TUNNEL_GRACE_PERIOD=10 cloudflared tunnel runcould not parse "10" as duration value for flag grace-period: time: missing unit in duration "10"cloudflared tunnel --grace-period 10 runcloudflared --version/--helpTests
TestRunAppInvalidGracePeriodEnvExitsNonZero(cmd/cloudflared/main_test.go): re-executes the test binary with
TUNNEL_GRACE_PERIOD=10via the helper-process pattern and asserts anon-zero exit code plus the error message. Fails without the fix (exit 0),
passes with it.
make test(go test -race ./...): 940 packages pass, 0 failures.go vet ./cmd/cloudflared/clean;golangci-lintreports no new issuesin the touched files.