diff --git a/buildpacks/golang.go b/buildpacks/golang.go index cb20b8df..9acbf2ab 100644 --- a/buildpacks/golang.go +++ b/buildpacks/golang.go @@ -111,7 +111,7 @@ func (bt GolangBuildTool) Install(ctx context.Context) (string, error) { log.Infof("Downloading from URL %s ...", downloadURL) localFile, err := t.DownloadFile(ctx, downloadURL) if err != nil { - log.Errorf("Error downloading file: %v", err) + log.Errorf("Unable to download: %v", err) return "", err } diff --git a/buildpacks/homebrew.go b/buildpacks/homebrew.go index c75a8571..cddf59d2 100644 --- a/buildpacks/homebrew.go +++ b/buildpacks/homebrew.go @@ -71,19 +71,19 @@ func (bt HomebrewBuildTool) PackagePrefix(ctx context.Context, packageString str err := t.Run(ctx, p) if err != nil { - return "", fmt.Errorf("Couldn't get prefix for package %s: %v", bt.pkgName, err) + return "", fmt.Errorf("getting prefix for package %s: %v", bt.pkgName, err) } err = bufWriter.Flush() if err != nil { - return "", fmt.Errorf("Couldn't get prefix for package %s: %v", bt.pkgName, err) + return "", fmt.Errorf("getting prefix for package %s: %v", bt.pkgName, err) } rd := bufio.NewReader(&buf) prefixPath, err := rd.ReadString('\n') if err != nil { - return "", fmt.Errorf("Couldn't get prefix for package %s: %v", bt.pkgName, err) + return "", fmt.Errorf("getting prefix for package %s: %v", bt.pkgName, err) } prefixPath = strings.TrimSuffix(prefixPath, "\n") bt.pkgPrefix = prefixPath @@ -134,11 +134,11 @@ func (bt HomebrewBuildTool) Install(ctx context.Context) (string, error) { case "linux": err = bt.installLinux(ctx, brewDir) default: - err = fmt.Errorf("Unsupported platform: %s", gi.GoOS) + err = fmt.Errorf("unsupported platform: %s", gi.GoOS) } if err != nil { - return "", fmt.Errorf("Unable to install Homebrew: %v", err) + return "", fmt.Errorf("installing Homebrew: %v", err) } if bt.IsPackage() { @@ -167,7 +167,7 @@ func (bt HomebrewBuildTool) InstallPackage(ctx context.Context, brewDir string) } err := t.Run(ctx, p) if err != nil { - return fmt.Errorf("Couldn't update brew: %v", err) + return fmt.Errorf("updating brew: %v", err) } pkgVersion := "" @@ -180,7 +180,7 @@ func (bt HomebrewBuildTool) InstallPackage(ctx context.Context, brewDir string) err = t.Run(ctx, p) if err != nil { - return fmt.Errorf("Couldn't intall %s@%s from Homebrew: %v", bt.pkgName, bt.version, err) + return fmt.Errorf("installing %s@%s from Homebrew: %v", bt.pkgName, bt.version, err) } return nil @@ -203,7 +203,7 @@ func (bt HomebrewBuildTool) installDarwin(ctx context.Context, brewDir string) e if err != nil { log.Errorf("Unable to clone brew!") - return fmt.Errorf("Couldn't clone brew: %v", err) + return fmt.Errorf("trying to clone brew: %v", err) } } @@ -236,7 +236,7 @@ func (bt HomebrewBuildTool) installLinux(ctx context.Context, brewDir string) er if err != nil { log.Errorf("Unable to clone brew!") - return fmt.Errorf("Couldn't clone brew: %v", err) + return fmt.Errorf("trying to clone brew: %v", err) } log.Infof("Updating brew") @@ -256,7 +256,7 @@ func (bt HomebrewBuildTool) Setup(ctx context.Context, brewDir string) error { if bt.IsPackage() { prefixPath, err := bt.PackagePrefix(ctx, bt.PackageVersionString()) if err != nil { - return fmt.Errorf("Unable to determine prefix for package %s: %v", bt.PackageVersionString(), err) + return fmt.Errorf("determining prefix for package %s: %v", bt.PackageVersionString(), err) } binDir := filepath.Join(prefixPath, "bin") sbinDir := filepath.Join(prefixPath, "sbin") diff --git a/buildpacks/python.go b/buildpacks/python.go index ef0888a4..05750ac2 100644 --- a/buildpacks/python.go +++ b/buildpacks/python.go @@ -69,7 +69,7 @@ func (bt PythonBuildTool) Install(ctx context.Context) (string, error) { Directory: setupDir, } if err := t.Run(ctx, p); err != nil { - return "", fmt.Errorf("Couldn't install python: %v", err) + return "", fmt.Errorf("installing python: %v", err) } } @@ -145,7 +145,7 @@ func (bt PythonBuildTool) Setup(ctx context.Context, condaDir string) error { if err := t.Run(ctx, p); err != nil { log.Errorf("Unable to run setup command: %s", cmd) - return fmt.Errorf("Unable to run '%s': %v", cmd, err) + return fmt.Errorf("running '%s': %v", cmd, err) } } } diff --git a/buildpacks/ruby.go b/buildpacks/ruby.go index 35ed92dd..0c692920 100644 --- a/buildpacks/ruby.go +++ b/buildpacks/ruby.go @@ -138,7 +138,7 @@ func (bt RubyBuildTool) Install(ctx context.Context) (string, error) { if err != nil { log.Infof("Unable to clone rbenv!") - return "", fmt.Errorf("Couldn't clone rbenv: %v", err) + return "", fmt.Errorf("trying to clone rbenv: %v", err) } } @@ -160,7 +160,7 @@ func (bt RubyBuildTool) Install(ctx context.Context) (string, error) { if err != nil { log.Errorf("Unable to clone ruby-build!") - return "", fmt.Errorf("Couldn't clone ruby-build: %v", err) + return "", fmt.Errorf("trying to clone ruby-build: %v", err) } } diff --git a/buildpacks/yarn.go b/buildpacks/yarn.go index 787b785f..e356cf57 100644 --- a/buildpacks/yarn.go +++ b/buildpacks/yarn.go @@ -2,7 +2,6 @@ package buildpacks import ( "context" - "fmt" "path/filepath" "github.com/yourbase/yb/plumbing/log" @@ -58,11 +57,13 @@ func (bt YarnBuildTool) Install(ctx context.Context) (string, error) { log.Infof("Downloading from URL %s...", downloadURL) localFile, err := t.DownloadFile(ctx, downloadURL) if err != nil { - return "", fmt.Errorf("Unable to download %s: %v", downloadURL, err) + log.Errorf("Unable to download: %v", err) + return "", err } if err := t.Unarchive(ctx, localFile, installDir); err != nil { - return "", fmt.Errorf("Unable to decompress archive: %v", err) + log.Errorf("Unable to decompress: %v", err) + return "", err } return yarnDir, nil diff --git a/cli/build.go b/cli/build.go index 601285ff..0948014b 100644 --- a/cli/build.go +++ b/cli/build.go @@ -184,7 +184,7 @@ func parseArgs(lonelyArg string) (pkgName, target string, err error) { parts := strings.SplitN(strings.TrimPrefix(lonelyArg, "@"), ":", 2) if len(parts) < 2 { - err = fmt.Errorf("unable to parse package/target definition: %s", lonelyArg) + err = fmt.Errorf("parsing package/target definition: %s", lonelyArg) return } pkgName = parts[0] diff --git a/cli/helpers.go b/cli/helpers.go index 9e81c1fd..a4059cb1 100644 --- a/cli/helpers.go +++ b/cli/helpers.go @@ -23,7 +23,7 @@ func GetTargetPackageNamed(file string) (Package, error) { _, pkgName := filepath.Split(currentPath) pkg, err := LoadPackage(pkgName, currentPath) if err != nil { - return Package{}, fmt.Errorf("Error loading package '%s': %v\n\nSee %s\n", pkgName, err, DOCS_URL) + return Package{}, fmt.Errorf("loading package '%s': %v\n\nSee %s\n", pkgName, err, DOCS_URL) } targetPackage = pkg } else { @@ -32,12 +32,12 @@ func GetTargetPackageNamed(file string) (Package, error) { if err != nil { - return Package{}, fmt.Errorf("Could not find valid configuration: %v\n\nTry running in the package root dir or writing the YML config file (%s) if it is missing. See %s", err, file, DOCS_URL) + return Package{}, fmt.Errorf("finding valid configuration: %v\n\nTry running in the package root dir or writing the YML config file (%s) if it is missing. See %s", err, file, DOCS_URL) } pkg, err := workspace.TargetPackage() if err != nil { - return Package{}, fmt.Errorf("Can't load workspace's target package: %v\n\nPackages under this Workspace may be missing a %s file or it's syntax is an invalid YML data. See %s", err, file, DOCS_URL) + return Package{}, fmt.Errorf("loading workspace's target package: %v\n\nPackages under this Workspace may be missing a %s file or it's syntax is an invalid YML data. See %s", err, file, DOCS_URL) } targetPackage = pkg diff --git a/config/config_file.go b/config/config_file.go index dd8a189c..44ca5bdd 100644 --- a/config/config_file.go +++ b/config/config_file.go @@ -30,7 +30,7 @@ func configFilePath() (string, error) { func loadConfigFile() (*ini.File, error) { iniPath, err := configFilePath() if err != nil { - return nil, fmt.Errorf("Couldn't determine config file path: %v", err) + return nil, fmt.Errorf("determining config file path: %v", err) } cfg, err := ini.Load(iniPath) @@ -57,7 +57,7 @@ func pathExists(path string) bool { func mkdirAsNeeded(dir string) error { if _, err := os.Stat(dir); os.IsNotExist(err) { if err := os.MkdirAll(dir, 0700); err != nil { - return fmt.Errorf("Unable to create dir: %v", err) + return fmt.Errorf("creating dir: %v", err) } } diff --git a/config/settings.go b/config/settings.go index a0c38aa8..91e36a91 100644 --- a/config/settings.go +++ b/config/settings.go @@ -80,10 +80,10 @@ func apiBaseUrl() (string, error) { case "": return "https://api.yourbase.io", nil default: - return "", fmt.Errorf("Unknown environment (%s) and no override in the config file or environment available", profile) + return "", fmt.Errorf("unknown environment (%s) and no override in the config file or environment available", profile) } - return "", fmt.Errorf("Unable to generate URL") + return "", fmt.Errorf("generating URL") } func ApiUrl(path string) (string, error) { @@ -92,7 +92,7 @@ func ApiUrl(path string) (string, error) { } if baseUrl, err := apiBaseUrl(); err != nil { - return "", fmt.Errorf("Can't determine API URL: %v", err) + return "", fmt.Errorf("determining API URL: %v", err) } else { return fmt.Sprintf("%s%s", baseUrl, path), nil } @@ -127,10 +127,10 @@ func managementBaseUrl() (string, error) { case "": return "https://app.yourbase.io", nil default: - return "", fmt.Errorf("Unknown environment (%s) and no override in the config file or environment available", profile) + return "", fmt.Errorf("unknown environment (%s) and no override in the config file or environment available", profile) } - return "", fmt.Errorf("Unable to generate URL") + return "", fmt.Errorf("generating URL") } func ManagementUrl(path string) (string, error) { @@ -139,7 +139,7 @@ func ManagementUrl(path string) (string, error) { } if baseUrl, err := managementBaseUrl(); err != nil { - return "", fmt.Errorf("Couldn't determine management URL: %v", err) + return "", fmt.Errorf("determining management URL: %v", err) } else { return fmt.Sprintf("%s%s", baseUrl, path), nil } @@ -174,7 +174,7 @@ func UserToken() (string, error) { token, err := GetConfigValue("user", "api_key") if err != nil { - return "", fmt.Errorf("Unable to find YB token in config file or environment.\nUse yb login to fetch one, if you already logged in to https://app.yourbase.io") + return "", fmt.Errorf("finding YB token in config file or environment.\nUse yb login to fetch one, if you already logged in to https://app.yourbase.io") } return token, nil @@ -182,5 +182,5 @@ func UserToken() (string, error) { return token, nil } - return "", fmt.Errorf("Unable to determine token - not in the config or environment") + return "", fmt.Errorf("determining token - not in the config or environment") } diff --git a/plumbing/patch_handle.go b/plumbing/patch_handle.go index ae3a7431..723906f0 100644 --- a/plumbing/patch_handle.go +++ b/plumbing/patch_handle.go @@ -15,17 +15,17 @@ import ( func applyPatch(file *diffparser.DiffFile, from string) (to string, err error) { if file == nil { - return "", fmt.Errorf("Needs a file to process") + return "", fmt.Errorf("no file to process") } lines := strings.Split(from, "\n") if len(lines) == 0 { - return "", fmt.Errorf("Won't process an empty string") + return "", fmt.Errorf("empty string") } var unmatchedLines int64 for _, hunk := range file.Hunks { idx := hunk.OrigRange.Start - 1 if idx < 0 { - return "", fmt.Errorf("Malformed patch, wrong start position (%d): %v\n", idx, strings.Join(file.Changes, "\n")) + return "", fmt.Errorf("wrong start position (%d): %v\n", idx, strings.Join(file.Changes, "\n")) } for i, line := range hunk.OrigRange.Lines { index := idx + i @@ -61,13 +61,13 @@ func applyPatch(file *diffparser.DiffFile, from string) (to string, err error) { // If the worktree isn't passsed it will try working on the local directory func UnifiedPatchOnGit(patch string, commit *object.Commit, w, originWorktree *git.Worktree, wd string) (patchError error) { if commit == nil && w == nil && wd == "" { - return fmt.Errorf("Nowhere to apply the patch on, please pass a git commit + git worktree, or a workdir to work on files") + return fmt.Errorf("no git commit + git worktree, or a workdir") } getCommitFileContents := func(file *diffparser.DiffFile) (contents string) { tree, err := commit.Tree() if err != nil { - patchError = fmt.Errorf("Unable to resolve commit tree: %v", err) + patchError = fmt.Errorf("resolving commit tree: %v", err) return "" } var workFile *object.File @@ -77,14 +77,14 @@ func UnifiedPatchOnGit(patch string, commit *object.Commit, w, originWorktree *g case diffparser.MODIFIED: workFile, err = tree.File(file.OrigName) if err != nil { - patchError = fmt.Errorf("Unable to retrieve tree entry %s: %v", file.OrigName, err) + patchError = fmt.Errorf("retrieving tree entry %s: %v", file.OrigName, err) return "" } contents, err = workFile.Contents() case diffparser.NEW: newFile, err := originWorktree.Filesystem.Open(file.NewName) if err != nil { - patchError = fmt.Errorf("Unable to open %s on the work tree: %v", file.NewName, err) + patchError = fmt.Errorf("opening %s in the work tree: %v", file.NewName, err) return "" } newBytes := bytes.NewBuffer(nil) @@ -93,7 +93,7 @@ func UnifiedPatchOnGit(patch string, commit *object.Commit, w, originWorktree *g _ = newFile.Close() } if err != nil { - patchError = fmt.Errorf("Couldn't get contents of %s: %v", file.OrigName, err) + patchError = fmt.Errorf("geting contents of %s: %v", file.OrigName, err) return "" } return @@ -102,7 +102,7 @@ func UnifiedPatchOnGit(patch string, commit *object.Commit, w, originWorktree *g // Detect in the patch string (unified) which files were affected and how diff, err := diffparser.Parse(patch) if err != nil { - return fmt.Errorf("Generated patch parse failed: %v", err) + return fmt.Errorf("patch parsing: %v", err) } for _, file := range diff.Files { @@ -111,25 +111,25 @@ func UnifiedPatchOnGit(patch string, commit *object.Commit, w, originWorktree *g case diffparser.DELETED: w.Remove(file.OrigName) case diffparser.MOVED: - return fmt.Errorf("Not implemented yet") + return fmt.Errorf("not implemented yet") default: contents := getCommitFileContents(file) if contents == "" && patchError != nil { - return fmt.Errorf("Unable to fetch contents from %s: %v", file, patchError) + return fmt.Errorf("fetching contents from %s: %v", file, patchError) } var fixedContents string if file.Mode == diffparser.MODIFIED { fixedContents, err = applyPatch(file, contents) if err != nil { - return fmt.Errorf("Apply Patch failed for <%s>: %v", file, err) + return fmt.Errorf("applying patch for <%s>: %v", file, err) } } if w != nil { newFile, err := w.Filesystem.Create(file.NewName) if err != nil { - return fmt.Errorf("Unable to open %s on the cloned tree: %v", file.NewName, err) + return fmt.Errorf("opening %s: %v", file.NewName, err) } var c string @@ -139,14 +139,14 @@ func UnifiedPatchOnGit(patch string, commit *object.Commit, w, originWorktree *g c = contents } if _, err = newFile.Write([]byte(c)); err != nil { - return fmt.Errorf("Unable to write patch hunk to %s: %v", file.NewName, err) + return fmt.Errorf("writing patch hunk to %s: %v", file.NewName, err) } _ = newFile.Close() w.Add(file.NewName) } else if wd != "" { //TODO Change file contents directly on the directory - return fmt.Errorf("Not implemented") + return fmt.Errorf("not implemented") } } } diff --git a/plumbing/progress.go b/plumbing/progress.go index 99b6d81b..8432e86c 100644 --- a/plumbing/progress.go +++ b/plumbing/progress.go @@ -1,5 +1,5 @@ // This came from https://raw.githubusercontent.com/BTBurke/clt/7f5151b6bef1b0da4b03f965b47cbe2de87a3ac0/progress.go -// NOTE the next steps in the field of UX for the CLI, we should consider moving to use clt +// TODO use github.com/urfave/cli/v2 + github.com/manifoldco/promptui + github.com/vbauerster/mpb package plumbing import ( diff --git a/plumbing/util.go b/plumbing/util.go index 6a8196c3..30fe7660 100644 --- a/plumbing/util.go +++ b/plumbing/util.go @@ -76,100 +76,6 @@ func RemoveWritePermission(path string) bool { return true } -/* -func PrintDownloadPercent(done chan int64, path string, total int64) { - - var stop bool = false - - for { - select { - case <-done: - stop = true - default: - - file, err := os.Open(path) - if err != nil { - log.Fatal(err) - } - - fi, err := file.Stat() - if err != nil { - log.Fatal(err) - } - - size := fi.Size() - - if size == 0 { - size = 1 - } - - var percent float64 = float64(size) / float64(total) * 100 - - fmt.Printf("%.0f", percent) - fmt.Println("%") - } - - if stop { - break - } - - time.Sleep(time.Second) - } -} - -func DownloadFile(dest string, url string) error { - - log.Printf("Downloading file %s from %s\n", dest, url) - - start := time.Now() - - out, err := os.Create(dest) - - if err != nil { - return fmt.Errorf("Unable to open destination '%s': %v\n", dest, err) - } - - defer out.Close() - - headResp, err := http.Head(url) - - if err != nil { - panic(err) - } - - defer headResp.Body.Close() - - size, err := strconv.Atoi(headResp.Header.Get("Content-Length")) - - if err != nil { - panic(err) - } - - done := make(chan int64) - - go PrintDownloadPercent(done, dest, int64(size)) - - resp, err := http.Get(url) - - if err != nil { - panic(err) - } - - defer resp.Body.Close() - - n, err := io.Copy(out, resp.Body) - - if err != nil { - panic(err) - } - - done <- n - - elapsed := time.Since(start) - log.Printf("Download completed in %s", elapsed) - return nil -} */ - /* * Look in the directory above the manifest file, if there's a config.yml, use that * otherwise we use the directory of the manifest file as the workspace root @@ -202,7 +108,7 @@ func FindWorkspaceRoot() (string, error) { } // No config in the parent of the package? No workspace! - return "", fmt.Errorf("No workspace root found nearby.") + return "", fmt.Errorf("searching for a workspace root") } func FindFileUpTree(filename string) (string, error) { @@ -220,7 +126,7 @@ func FindFileUpTree(filename string) (string, error) { wd = filepath.Dir(wd) if strings.HasSuffix(wd, "/") { - return "", fmt.Errorf("Can't find %s, ended up at the root...", filename) + return "", fmt.Errorf("searching %s, ended up at the root", filename) } } } @@ -248,11 +154,11 @@ func CompressBuffer(b *bytes.Buffer) error { xzWriter, err := xz.NewWriter(&buf) if err != nil { - return fmt.Errorf("Unable to compress data: %s\n", err) + return fmt.Errorf("compressing data: %s\n", err) } if _, err := io.Copy(xzWriter, b); err != nil { - return fmt.Errorf("Unable to compress data: %s\n", err) + return fmt.Errorf("compressing data: %s\n", err) } xzWriter.Close() @@ -266,13 +172,13 @@ func DecompressBuffer(b *bytes.Buffer) error { xzReader, err := xz.NewReader(b) if err != nil { - return fmt.Errorf("Unable to decompress data: %s\n", err) + return fmt.Errorf("decompressing data: %s\n", err) } var buf bytes.Buffer if _, err := io.Copy(&buf, xzReader); err != nil { - return fmt.Errorf("Unable to decompress data: %v", err) + return fmt.Errorf("decompressing data: %v", err) } b.Reset() @@ -294,7 +200,7 @@ func SaneEnvironmentVar(env string) (name, value string, sane bool) { func CloneRepository(remote GitRemote, inMem bool, basePath string) (rep *git.Repository, err error) { if remote.Branch == "" { - return nil, fmt.Errorf("No branch defined to clone repo %v", remote.Url) + return nil, fmt.Errorf("define a branch to clone repo %v", remote.Url) } cloneOpts := &git.CloneOptions{ @@ -326,7 +232,7 @@ func CloneRepository(remote GitRemote, inMem bool, basePath string) (rep *git.Re rep, err = git.PlainClone(basePath, false, cloneOpts) } if err != nil && strings.Count(err.Error(), "SSH") > 0 { - err = fmt.Errorf("Please check your SSH agent/key configuration") + err = fmt.Errorf("searching for a SSH agent/key configuration") } return diff --git a/runtime/containers.go b/runtime/containers.go index 9f92bc08..0d245d9b 100644 --- a/runtime/containers.go +++ b/runtime/containers.go @@ -142,7 +142,7 @@ func (t *ContainerTarget) UploadFile(ctx context.Context, src string, dest strin log.Infof("Uploading %s to %s", src, dest) err := narwhal.UploadFile(ctx, narwhal.DockerClient(), t.Container.Id, dest, src) if err != nil { - return fmt.Errorf("Couldn't upload file to container: %v", err) + return fmt.Errorf("uploading file to container: %v", err) } log.Infof("Done") return nil @@ -345,7 +345,7 @@ func ForwardUnixSocketToTcp(unixSocket string) (string, error) { for { conn, err := l.Accept() if err != nil { - log.Errorf("accept failed: %s", err) + log.Errorf("Accept failed: %s", err) continue } @@ -353,7 +353,7 @@ func ForwardUnixSocketToTcp(unixSocket string) (string, error) { defer conn.Close() uconn, err := net.Dial("unix", unixSocket) if err != nil { - log.Warnf("unix dial failed: %s", err) + log.Warnf("UNIX dial failed: %s", err) return } log.Infof("Opened %s", unixSocket) diff --git a/runtime/download.go b/runtime/download.go index 34cbbc07..1892bf10 100644 --- a/runtime/download.go +++ b/runtime/download.go @@ -29,7 +29,7 @@ func localCacheDir() string { func cacheFilenameForURL(url string) (string, error) { reg, err := regexp.Compile("[^a-zA-Z0-9.]+") if err != nil { - return "", fmt.Errorf("Can't compile regex: %v", err) + return "", fmt.Errorf("compiling regex: %v", err) } fileName := reg.ReplaceAllString(url, "") return fileName, nil @@ -65,7 +65,7 @@ func downloadFileWithCache(ctx context.Context, url string) (string, error) { } if err := resp.Body.Close(); err != nil { // Non fatal - log.Warnf("trying to close response body: %v", err) + log.Warnf("Trying to close response body: %v", err) } // checks response HTTP status // TODO add support for retrying and resuming partial downloads diff --git a/runtime/metal.go b/runtime/metal.go index 3e47685e..22f8d21d 100644 --- a/runtime/metal.go +++ b/runtime/metal.go @@ -190,7 +190,7 @@ func (t *MetalTarget) ExecToStdoutWithEnv(ctx context.Context, cmdString string, log.Infof("Running: %s in %s", cmdString, targetDir) cmdArgs, err := shlex.Split(cmdString) if err != nil { - return fmt.Errorf("Can't parse command string '%s': %v", cmdString, err) + return fmt.Errorf("parsing command string '%s': %v", cmdString, err) } cmd := exec.CommandContext(ctx, cmdArgs[0], cmdArgs[1:len(cmdArgs)]...) @@ -205,7 +205,7 @@ func (t *MetalTarget) ExecToStdoutWithEnv(ctx context.Context, cmdString string, err = cmd.Run() if err != nil { - return fmt.Errorf("Command failed to run with error: %v", err) + return fmt.Errorf("command failed to run: %v", err) } return nil @@ -219,12 +219,12 @@ func (t *MetalTarget) ExecToLog(ctx context.Context, cmdString string, targetDir cmdArgs, err := shlex.Split(cmdString) if err != nil { - return fmt.Errorf("Can't parse command string '%s': %v", cmdString, err) + return fmt.Errorf("parsing command string '%s': %v", cmdString, err) } logfile, err := os.OpenFile(logPath, os.O_RDWR|os.O_CREATE, 0644) if err != nil { - return fmt.Errorf("Couldn't open log file %s: %v", logPath, err) + return fmt.Errorf("opening log file %s: %v", logPath, err) } defer logfile.Close() @@ -238,7 +238,7 @@ func (t *MetalTarget) ExecToLog(ctx context.Context, cmdString string, targetDir err = cmd.Run() if err != nil { - return fmt.Errorf("Command '%s' failed to run with error -- see log for information: %s", cmdString, logPath) + return fmt.Errorf("command '%s' failed to run with error -- see log for information: %s", cmdString, logPath) } return nil @@ -252,7 +252,7 @@ func (t *MetalTarget) ExecSilently(ctx context.Context, cmdString string, target func (t *MetalTarget) ExecSilentlyToWriter(ctx context.Context, cmdString string, targetDir string, writer io.Writer) error { cmdArgs, err := shlex.Split(cmdString) if err != nil { - return fmt.Errorf("Can't parse command string '%s': %v", cmdString, err) + return fmt.Errorf("parsing command string '%s': %v", cmdString, err) } cmd := exec.CommandContext(ctx, cmdArgs[0], cmdArgs[1:len(cmdArgs)]...) @@ -264,7 +264,7 @@ func (t *MetalTarget) ExecSilentlyToWriter(ctx context.Context, cmdString string err = cmd.Run() if err != nil { - return fmt.Errorf("Command '%s' failed to run with error %v", cmdString, err) + return fmt.Errorf("command '%s' failed to run: %v", cmdString, err) } return nil diff --git a/runtime/runtime.go b/runtime/runtime.go index 3906b741..2ad7a325 100644 --- a/runtime/runtime.go +++ b/runtime/runtime.go @@ -83,7 +83,7 @@ func (r *Runtime) NTargets() int { func (r *Runtime) AddTarget(targetId string, t Target) error { if _, exists := r.Targets[targetId]; exists { - return fmt.Errorf("Unable to add target with id %s - already exists", targetId) + return fmt.Errorf("adding target with id %s - already exists", targetId) } r.Targets[targetId] = t @@ -99,7 +99,7 @@ func (r *Runtime) RunInTarget(ctx context.Context, p Process, targetId string) e if target, exists := r.Targets[targetId]; exists { return target.Run(ctx, p) } else { - return fmt.Errorf("Unable to find target %s in runtime", targetId) + return fmt.Errorf("finding target %s in runtime", targetId) } } diff --git a/selfupdate/main.go b/selfupdate/main.go index 6577dd53..b0ba1b0e 100644 --- a/selfupdate/main.go +++ b/selfupdate/main.go @@ -1,3 +1,4 @@ +// TODO use GoReleaser + github.com/rhysd/go-github-selfupdate instead of Equinox package selfupdate import ( diff --git a/types/worktreesave.go b/types/worktreesave.go index 93ec231d..b0d097b8 100644 --- a/types/worktreesave.go +++ b/types/worktreesave.go @@ -20,7 +20,7 @@ func (w *WorktreeSave) Add(file string) (err error) { if w.Enabled { fullPath := filepath.Join(w.Path, file) if !pathExists(fullPath) { - err = fmt.Errorf("Path %v, for saving worktree state, doesn't exist", fullPath) + err = fmt.Errorf("path %v, for saving worktree state, doesn't exist", fullPath) return } w.Files = append(w.Files, file) @@ -38,7 +38,7 @@ func (w *WorktreeSave) Save() (worktreeSaveFile string, err error) { worktreeSaveFile = filepath.Join(w.Path, fmt.Sprintf(".yb-worktreesave-%s.tar", w.Hash)) err = tar.Archive(w.Files, worktreeSaveFile) } else { - err = fmt.Errorf("Need files and a commit hash") + err = fmt.Errorf("no files nor commit hash") } } return @@ -47,7 +47,7 @@ func (w *WorktreeSave) Save() (worktreeSaveFile string, err error) { func (w *WorktreeSave) Restore(pkgFile string) (err error) { if w.Enabled { if !pathExists(pkgFile) || !pathExists(w.Path) { - err = fmt.Errorf("Path doesn't exist: %v or %v", pkgFile, w.Path) + err = fmt.Errorf("path doesn't exist: %v or %v", pkgFile, w.Path) return } @@ -60,12 +60,12 @@ func (w *WorktreeSave) Restore(pkgFile string) (err error) { func NewWorktreeSave(path string, hash string, enabled bool) (w *WorktreeSave, err error) { if enabled { if !pathExists(path) { - err = fmt.Errorf("Path '%v', for saving worktree state, doesn't exist", path) + err = fmt.Errorf("path '%v', for saving worktree state, doesn't exist", path) return } if len(hash) == 0 { - err = fmt.Errorf("Need a commit hash") + err = fmt.Errorf("no commit hash") return } } diff --git a/workspace/build_manifest.go b/workspace/build_manifest.go index 75e357b8..28451d6c 100644 --- a/workspace/build_manifest.go +++ b/workspace/build_manifest.go @@ -164,7 +164,7 @@ func (b BuildManifest) CIBuild(buildName string) (CIBuild, error) { return build, nil } } - return CIBuild{}, fmt.Errorf("No such CI build '%s' in build manifest", buildName) + return CIBuild{}, fmt.Errorf("no such CI build '%s' in build manifest", buildName) } func (b BuildManifest) BuildTarget(targetName string) (BuildTarget, error) { @@ -173,7 +173,7 @@ func (b BuildManifest) BuildTarget(targetName string) (BuildTarget, error) { return target, nil } } - return BuildTarget{}, fmt.Errorf("No such target '%s' in build manifest", targetName) + return BuildTarget{}, fmt.Errorf("no such target '%s' in build manifest", targetName) } func (b BuildManifest) BuildTargetList() []string { diff --git a/workspace/build_target.go b/workspace/build_target.go index d21800a7..ae47d1a1 100644 --- a/workspace/build_target.go +++ b/workspace/build_target.go @@ -197,7 +197,7 @@ func (bt BuildTarget) Build(ctx context.Context, runtimeCtx *runtime.Runtime, ou } stepTimes = append(stepTimes, errorTimer) - return stepTimes, fmt.Errorf("can't add container %s: %v", cd.Label, err) + return stepTimes, fmt.Errorf("adding container %s: %v", cd.Label, err) } } diff --git a/workspace/buildpack_loader.go b/workspace/buildpack_loader.go index 37c6fe08..cd56e8ff 100644 --- a/workspace/buildpack_loader.go +++ b/workspace/buildpack_loader.go @@ -81,14 +81,14 @@ func LoadBuildPacks(ctx context.Context, installTarget runtime.Target, dependenc case "protoc": bt = buildpacks.NewProtocBuildTool(spec) default: - return setupTimers, fmt.Errorf("Unknown build tool: %s\n", toolSpec) + return setupTimers, fmt.Errorf("unknown build tool: %s\n", toolSpec) } // Install if needed startTime := time.Now() installedDir, err := bt.Install(ctx) if err != nil { - return setupTimers, fmt.Errorf("Unable to install tool %s: %v", toolSpec, err) + return setupTimers, fmt.Errorf("installing tool %s: %v", toolSpec, err) } endTime := time.Now() setupTimers = append(setupTimers, CommandTimer{ @@ -100,7 +100,7 @@ func LoadBuildPacks(ctx context.Context, installTarget runtime.Target, dependenc // Setup build tool (paths, env, etc) startTime = time.Now() if err := bt.Setup(ctx, installedDir); err != nil { - return setupTimers, fmt.Errorf("Unable to setup tool %s: %v", toolSpec, err) + return setupTimers, fmt.Errorf("setting up tool %s: %v", toolSpec, err) } endTime = time.Now() setupTimers = append(setupTimers, CommandTimer{ diff --git a/workspace/package.go b/workspace/package.go index 75cbdb3a..dc3fd1ee 100644 --- a/workspace/package.go +++ b/workspace/package.go @@ -89,7 +89,7 @@ func LoadPackage(name string, path string) (Package, error) { buildyaml, _ := ioutil.ReadFile(buildYaml) err := yaml.Unmarshal([]byte(buildyaml), &manifest) if err != nil { - return Package{}, fmt.Errorf("Error loading %s for %s: %v", MANIFEST_FILE, name, err) + return Package{}, fmt.Errorf("loading %s for %s: %v", MANIFEST_FILE, name, err) } p := Package{ @@ -167,12 +167,12 @@ func (p Package) createExecutionTarget(ctx context.Context, runtimeCtx *runtime. for _, cd := range containers { cd.LocalWorkDir = localContainerWorkDir if err := p.checkMounts(&cd, localContainerWorkDir); err != nil { - return nil, fmt.Errorf("Unable to set host container mount dir: %v", err) + return nil, fmt.Errorf("set host container mount dir: %v", err) } _, err := runtimeCtx.AddContainer(ctx, cd) if err != nil { - return nil, fmt.Errorf("Couldn't start container dependency: %v", err) + return nil, fmt.Errorf("starting container dependency: %v", err) } } @@ -224,13 +224,13 @@ func (p Package) createExecutionTarget(ctx context.Context, runtimeCtx *runtime. sourceMapDir = execContainer.WorkDir } if err := p.checkMounts(&execContainer, p.Path()); err != nil { - return nil, fmt.Errorf("Unable to set host container mount dir: %v", err) + return nil, fmt.Errorf("set host container mount dir: %v", err) } p.addMount(&execContainer, p.Path(), sourceMapDir, "package") execTarget, err := runtimeCtx.AddContainer(ctx, execContainer) if err != nil { - return nil, fmt.Errorf("Couldn't start exec container: %v", err) + return nil, fmt.Errorf("starting exec container: %v", err) } LoadBuildPacks(ctx, execTarget, p.Manifest.Dependencies.Build) diff --git a/workspace/workspace.go b/workspace/workspace.go index 6c1ebe3b..ed072d34 100644 --- a/workspace/workspace.go +++ b/workspace/workspace.go @@ -95,7 +95,7 @@ func (w Workspace) TargetPackage() (Package, error) { if w.Target != "" { return w.PackageByName(w.Target) } else { - return Package{}, fmt.Errorf("No default package specified for the workspace") + return Package{}, fmt.Errorf("no default package specified for the workspace") } } @@ -106,7 +106,7 @@ func (w Workspace) PackageByName(name string) (Package, error) { } } - return Package{}, fmt.Errorf("No package with name %s found in the workspace", name) + return Package{}, fmt.Errorf("no package with name %s found in the workspace", name) } func (w Workspace) PackageList() []Package { @@ -146,7 +146,7 @@ func loadWorkspaceFromPackage(manifestFile string, path string) (Workspace, erro pkg.Workspace = &workspace if err != nil { - return workspace, fmt.Errorf("Couldn't load package for workspace: %v", err) + return workspace, fmt.Errorf("loading package for workspace: %v", err) } workspacesRoot, exists := os.LookupEnv("YB_WORKSPACES_ROOT") @@ -176,7 +176,7 @@ func loadWorkspaceFromConfigYaml(configFile string, path string) (Workspace, err err := yaml.Unmarshal([]byte(configyaml), &workspace) if err != nil { - return Workspace{}, fmt.Errorf("Error loading workspace config!") + return Workspace{}, fmt.Errorf("loading workspace config!") } workspace.Path = path