diff --git a/cmd/cloudflared/config/configuration.go b/cmd/cloudflared/config/configuration.go index 3ff9159a..3715ec6c 100644 --- a/cmd/cloudflared/config/configuration.go +++ b/cmd/cloudflared/config/configuration.go @@ -391,7 +391,7 @@ func ReadConfigFile(c *cli.Context, log logger.Service) (*configFileSettings, er } defer file.Close() if err := yaml.NewDecoder(file).Decode(&configuration); err != nil { - return nil, errors.Wrap(err, "error parsing config file at "+configFile) + return nil, errors.Wrap(err, "error parsing YAML in config file at "+configFile) } configuration.sourceFile = configFile return &configuration, nil diff --git a/cmd/cloudflared/config/manager.go b/cmd/cloudflared/config/manager.go index a286ab48..cd4faa9d 100644 --- a/cmd/cloudflared/config/manager.go +++ b/cmd/cloudflared/config/manager.go @@ -1,11 +1,11 @@ package config import ( - "errors" "os" "github.com/cloudflare/cloudflared/logger" "github.com/cloudflare/cloudflared/watcher" + "github.com/pkg/errors" "gopkg.in/yaml.v2" ) @@ -80,7 +80,7 @@ func readConfigFromPath(configPath string) (Root, error) { var config Root if err := yaml.NewDecoder(file).Decode(&config); err != nil { - return Root{}, err + return Root{}, errors.Wrap(err, "error parsing YAML in config file at "+configPath) } return config, nil diff --git a/cmd/cloudflared/tunnel/subcommand_context.go b/cmd/cloudflared/tunnel/subcommand_context.go index 5a1f6308..5774bced 100644 --- a/cmd/cloudflared/tunnel/subcommand_context.go +++ b/cmd/cloudflared/tunnel/subcommand_context.go @@ -20,6 +20,15 @@ import ( "github.com/cloudflare/cloudflared/tunnelstore" ) +type errInvalidJSONCredential struct { + err error + path string +} + +func (e errInvalidJSONCredential) Error() string { + return "Invalid JSON when parsing tunnel credentials file" +} + // subcommandContext carries structs shared between subcommands, to reduce number of arguments needed to // pass between subcommands, and make sure they are only initialized once type subcommandContext struct { @@ -111,7 +120,7 @@ func (sc *subcommandContext) readTunnelCredentials(tunnelID uuid.UUID) (*pogs.Tu var auth pogs.TunnelAuth if err = json.Unmarshal(body, &auth); err != nil { - return nil, err + return nil, errInvalidJSONCredential{path: filePath, err: err} } return &auth, nil } @@ -244,6 +253,10 @@ func (sc *subcommandContext) delete(tunnelIDs []uuid.UUID) error { func (sc *subcommandContext) run(tunnelID uuid.UUID) error { credentials, err := sc.readTunnelCredentials(tunnelID) if err != nil { + if e, ok := err.(errInvalidJSONCredential); ok { + sc.logger.Errorf("The credentials file at %s contained invalid JSON. This is probably caused by passing the wrong filepath. Reminder: the credentials file is a .json file created via `cloudflared tunnel create`.", e.path) + sc.logger.Errorf("Invalid JSON when parsing credentials file: %s", e.err.Error()) + } return err }