X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=main.go;h=2d0c1799fbb41cff765698461dec2eb43a485998;hb=bbd16c4e5951055ed73f7282dfd22cc4b3ab5700;hp=c8effe627e94a7af7c1077c9fb5ca4a40309e26a;hpb=f48c7c3164b0568de45d7ccc88b0ce7724a17cc4;p=src%2Fxds%2Fxds-cli.git diff --git a/main.go b/main.go index c8effe6..2d0c179 100644 --- a/main.go +++ b/main.go @@ -232,11 +232,16 @@ func main() { // Load config file if requested if confFile != "" { earlyPrintf("confFile detected: %v", confFile) + confFile, err := common.ResolveEnvVar(confFile) + if err != nil { + exitError(1, "Error while resolving confFile: %v", err) + } + earlyPrintf("Resolved confFile: %v", confFile) if !common.Exists(confFile) { exitError(1, "Error env config file not found") } // Load config file variables that will overwrite env variables - err := godotenv.Overload(confFile) + err = godotenv.Overload(confFile) if err != nil { exitError(1, "Error loading env config file "+confFile) } @@ -315,6 +320,11 @@ func XdsConnInit(ctx *cli.Context) error { serverURL = "http://" + serverURL } + lvl := common.HTTPLogLevelWarning + if Log.Level == logrus.DebugLevel { + lvl = common.HTTPLogLevelDebug + } + // Create HTTP client Log.Debugln("Connect HTTP client on ", agentURL) conf := common.HTTPClientConfig{ @@ -323,15 +333,22 @@ func XdsConnInit(ctx *cli.Context) error { CsrfDisable: true, LogOut: Log.Out, LogPrefix: "XDSAGENT: ", - LogLevel: common.HTTPLogLevelWarning, + LogLevel: lvl, } HTTPCli, err = common.HTTPNewClient(agentURL, conf) if err != nil { errmsg := err.Error() - if m, err := regexp.MatchString("Get http.?://", errmsg); m && err == nil { + m, err := regexp.MatchString("Get http.?://", errmsg) + if (m && err == nil) || strings.Contains(errmsg, "Failed to get device ID") { i := strings.LastIndex(errmsg, ":") - errmsg = "Cannot connection to " + agentURL + errmsg[i:] + newErr := "Cannot connection to " + agentURL + if i > 0 { + newErr += " (" + strings.TrimSpace(errmsg[i+1:]) + ")" + } else { + newErr += " (" + strings.TrimSpace(errmsg) + ")" + } + errmsg = newErr } return cli.NewExitError(errmsg, 1) }