Fail loudly on an unparseable SENTRY_DSN and a malformed .env (closes #283)
check / check (push) Successful in 2m54s
check / check (push) Successful in 2m54s
This commit was merged in pull request #289.
This commit is contained in:
+22
-1
@@ -54,6 +54,11 @@ const stopTimeout = 5 * time.Second
|
||||
// caller can tell "called wrong" from "declined".
|
||||
const exitUsage = 2
|
||||
|
||||
// helpCommand is the subcommand that prints usage. The flag spellings
|
||||
// beside it in the switch are aliases; this is the name the usage text
|
||||
// documents and the one tests invoke.
|
||||
const helpCommand = "help"
|
||||
|
||||
// Build-time variables set via -ldflags.
|
||||
//
|
||||
//nolint:gochecknoglobals // Build-time variables injected by the linker.
|
||||
@@ -75,11 +80,27 @@ func main() {
|
||||
// every existing deployment invoke; that path is unchanged, including
|
||||
// where the DATA_DIR lock is taken relative to building the fx graph
|
||||
// and how fx propagates a non-zero exit itself.
|
||||
//
|
||||
// The optional .env file is read here, before any subcommand and so
|
||||
// before anything reads the environment — config.DataDir, which both
|
||||
// the DATA_DIR lock and resetpw call outside the fx graph, above all.
|
||||
// It used to be read from an init() in internal/config, which put it
|
||||
// earlier still but threw the error away: a single malformed line
|
||||
// applied none of the file and said nothing about it. A file that is
|
||||
// not there stays fine, since .env is optional and most deployments
|
||||
// do not have one.
|
||||
func dispatch(
|
||||
args []string,
|
||||
stdin io.Reader,
|
||||
stdout, stderr io.Writer,
|
||||
) int {
|
||||
err := config.LoadDotEnv()
|
||||
if err != nil {
|
||||
_, _ = fmt.Fprintf(stderr, "%s: %v\n", appname, err)
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
if len(args) == 0 {
|
||||
return run(stderr)
|
||||
}
|
||||
@@ -87,7 +108,7 @@ func dispatch(
|
||||
switch args[0] {
|
||||
case resetpw.Name:
|
||||
return resetpw.Run(args[1:], stdin, stdout, stderr)
|
||||
case "help", "-h", "-help", "--help":
|
||||
case helpCommand, "-h", "-help", "--help":
|
||||
usage(stdout)
|
||||
|
||||
return 0
|
||||
|
||||
Reference in New Issue
Block a user