Skip to content
This repository has been archived by the owner on Jan 14, 2020. It is now read-only.

Commit

Permalink
updated error messages with more info
Browse files Browse the repository at this point in the history
  • Loading branch information
ojkelly committed Jul 13, 2018
1 parent b88a0e1 commit 4216544
Show file tree
Hide file tree
Showing 18 changed files with 81 additions and 87 deletions.
7 changes: 6 additions & 1 deletion documentation/content/concepts/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,9 @@ An example of when you may want to do this, is to get the latest AMI for a set o

[1]: https://golang.org/pkg/plugin/
[2]: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-custom-resources.html
[3]: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/walkthrough-custom-resources-lambda-lookup-amiids.html
[3]: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/walkthrough-custom-resources-lambda-lookup-amiids.html


## Cache

Kombustion caches downloaded plugins in `~/.kombustion/cache/plugins`.
5 changes: 3 additions & 2 deletions internal/cloudformation/tasks/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func GetCloudformationClient(profile string, region string) *cloudformation.Clou
fmt.Sprintf(
"Pass a region in via the cli with `--region us-east-1` or set a default `region` in kombustion.yaml",
),
"http://kombustion.io/manifest#region",
"http://kombustion.io/manifest/#region",
)
}

Expand Down Expand Up @@ -100,10 +100,11 @@ func must(sess *session.Session, err error) *session.Session {
printer.Fatal(
err,
"You need to provide access credentials to your AWS account.",
"",
"https://www.kombustion.io/docs/getting-started/#ensuring-your-credentials-are-available",
)
}

// TODO: Make this error more helpful
printer.Fatal(
err,
"",
Expand Down
2 changes: 2 additions & 0 deletions internal/cloudformation/tasks/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func checkError(err error) {
"",
)
} else {
// TODO: Make this error more helpful
printer.Fatal(err, "", "")
}
}
Expand All @@ -43,6 +44,7 @@ func checkErrorDeletePoll(err error) {
)
os.Exit(0)
} else {
// TODO: Make this error more helpful
printer.Fatal(err, "", "")
}
}
Expand Down
4 changes: 2 additions & 2 deletions internal/core/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func Update(currentVersion string, noPrompt bool) {
}

if confirm {
printer.Progress(fmt.Sprintf("Downloading %s", downloadURL))
printer.Progress(fmt.Sprintf("Downloading %s", *latestRelease.TagName))

// TODO: Codesign the update, and check it here

Expand Down Expand Up @@ -220,7 +220,7 @@ func extractRelease(url, fileName string) (string, error) {
func surveyToConfirmUpdate(version string) bool {
var update bool
prompt := &survey.Confirm{
Message: fmt.Sprintf("Update to version %s?", version),
Message: fmt.Sprintf(" ├─ Update to version %s?", version),
}
survey.AskOne(prompt, &update, nil)
return update
Expand Down
4 changes: 3 additions & 1 deletion internal/genplugin/genplugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import (
"go/format"
"io/ioutil"

printer "github.com/KablamoOSS/go-cli-printer"
"os"
"os/exec"
"reflect"
"strings"
printer "github.com/KablamoOSS/go-cli-printer"

"github.com/KablamoOSS/kombustion/types"
yaml "github.com/KablamoOSS/yaml"
Expand Down Expand Up @@ -196,6 +196,7 @@ func main() {

err := app.Run(os.Args)
if err != nil {
// TODO: Make this error more helpful
printer.Fatal(
err,
"",
Expand Down Expand Up @@ -393,6 +394,7 @@ func writeOutput(path string, output []byte) {

func checkError(err error) {
if err != nil {
// TODO: Make this error more helpful
printer.Fatal(
err,
"",
Expand Down
2 changes: 1 addition & 1 deletion internal/manifest/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func InitaliseNewManifest() error {
printer.Fatal(
fmt.Errorf("Sorry we can't create a new kombustion.yaml, one already exists."),
"If you want to re-initialise your kombustion.yaml file, first remove it.",
"https://kombustion.io/manifest",
"https://www.kombustion.io/api/manifest/",
)
}

Expand Down
4 changes: 2 additions & 2 deletions internal/manifest/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ func FindAndLoadManifest() *Manifest {
printer.Fatal(
err,
"If you want to re-initialise your kombustion.yaml file, first remove it.",
"https://kombustion.io/manifest",
"https://www.kombustion.io/api/manifest/",
)
}
manifest, err := findAndLoadManifest(path)
if err != nil {
printer.Fatal(
err,
"If you want to re-initialise your kombustion.yaml file, first remove it.",
"https://kombustion.io/manifest",
"https://www.kombustion.io/api/manifest/",
)
}
loadedManifest = &manifest
Expand Down
8 changes: 3 additions & 5 deletions internal/plugins/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,8 @@ func AddPluginsToManifest(manifest *manifestType.Manifest, pluginLocations []str
printer.Progress("Kombusting")

// Get the lockFile
lockFile, err := lock.FindAndLoadLock()
if err != nil {
printer.Error(err, config.ErrorHelpInfo, "")
return manifest, err
}
lockFile := lock.FindAndLoadLock()
var err error

// Add all the plugins to the manifest and lockfile
manifest, lockFile, err = addPluginsToManifestAndLock(manifest, lockFile, pluginLocations)
Expand Down Expand Up @@ -116,6 +113,7 @@ func constructGithubPlugin(

latestRelease, latestReleaseErr := core.GetLatestRelease(githubClient, githubOrg, githubProject)
if latestReleaseErr != nil {
// TODO: Make this error more helpful
printer.Fatal(
latestReleaseErr,
"",
Expand Down
1 change: 1 addition & 0 deletions internal/plugins/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func findPluginInCache(plugin lock.Plugin, resolved lock.PluginResolution) (foun
func GetCacheDir() string {
usr, err := user.Current()
if err != nil {
// TODO: Make this error more helpful
printer.Fatal(
err,
"",
Expand Down
12 changes: 6 additions & 6 deletions internal/plugins/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ func ExtractResourcesFromPlugins(
printer.Fatal(
fmt.Errorf("Plugin `%s` tried to load resource `%s` but it already exists", plugin.Config.Name, pluginKey),
fmt.Sprintf(
"You can add a `prefix` to this plugin in kombustion.yaml to resolve this.",
"You can add a `Alias` to this plugin in kombustion.yaml to resolve this.",
),
"",
"https://www.kombustion.io/api/manifest/#alias-optional",
)
} else {
wrappedParserFunc := func(
Expand Down Expand Up @@ -54,9 +54,9 @@ func ExtractMappingsFromPlugins(
printer.Fatal(
fmt.Errorf("Plugin `%s` tried to load mapping `%s` but it already exists", plugin.Config.Name, pluginKey),
fmt.Sprintf(
"You can add a `prefix` to this plugin in kombustion.yaml to resolve this.",
"You can add a `Alias` to this plugin in kombustion.yaml to resolve this.",
),
"",
"https://www.kombustion.io/api/manifest/#alias-optional",
)
} else {
wrappedParserFunc := func(
Expand Down Expand Up @@ -90,9 +90,9 @@ func ExtractOutputsFromPlugins(
printer.Fatal(
fmt.Errorf("Plugin `%s` tried to load output `%s` but it already exists", plugin.Config.Name, pluginKey),
fmt.Sprintf(
"You can add a `prefix` to this plugin in kombustion.yaml to resolve this.",
"You can add a `Alias` to this plugin in kombustion.yaml to resolve this.",
),
"",
"https://www.kombustion.io/api/manifest/#alias-optional",
)
} else {
wrappedParserFunc := func(
Expand Down
22 changes: 15 additions & 7 deletions internal/plugins/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,22 @@ func InstallPlugins() error {
printer.Step("Installing plugins")
printer.Progress("Kombusting")

lockFile, err := lock.FindAndLoadLock()
if err != nil {
return err
}
lockFile := lock.FindAndLoadLock()

updatedLockFile, installErrors := installPluginsWithLock(lockFile)
if len(installErrors) > 0 {
for _, err := range installErrors {
printer.Error(err, "", "")
}
printer.Fatal(err, "Error installing plugins", "")

// TODO: This error message could be more helpful
printer.Fatal(
fmt.Errorf("Failed installing plugins."),
"Error installing plugins",
"",
)
}
err = lock.WriteLockToDisk(updatedLockFile)
err := lock.WriteLockToDisk(updatedLockFile)
if err != nil {
printer.Fatal(err, "Error installing plugins", "")
return err
Expand Down Expand Up @@ -85,7 +89,11 @@ func installPlugin(plugin lock.Plugin) (updatedPlugin lock.Plugin, installErrors
// Check the local cache for a file
foundInCache, cacheFile, err := findPluginInCache(plugin, resolved)
if err != nil {
printer.Fatal(err, "", "")
printer.Fatal(
err,
"Try again, if this error persists try clearing the plugin cache.",
"https://www.kombustion.io/concepts/plugins/#cache",
)
installErrors = append(installErrors, err)
}

Expand Down
23 changes: 19 additions & 4 deletions internal/plugins/lock/load.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,40 @@
package lock

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"

printer "github.com/KablamoOSS/go-cli-printer"
"github.com/KablamoOSS/kombustion/config"
"github.com/KablamoOSS/yaml"
)

// FindAndLoadLock - Search the current directory for a Lock file, and load it
// If no lock is found, return an empty Lock
func FindAndLoadLock() (lock *Lock, err error) {
func FindAndLoadLock() (lock *Lock) {
var err error

path, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
printer.Fatal(err, config.ErrorHelpInfo, "")
printer.Fatal(
err,
fmt.Sprintf(
"kombustion.lock may need to be corrupted and needs to be rebuilt. Run `kombustion install` to fix this.",
),
"https://www.kombustion.io/api/cli/#install",
)
}

lock, err = findAndLoadLock(path)
if err != nil {
printer.Fatal(err, config.ErrorHelpInfo, "")
printer.Fatal(
err,
fmt.Sprintf(
"kombustion.lock may need to be corrupted and needs to be rebuilt. Run `kombustion install` to fix this.",
),
"https://www.kombustion.io/api/cli/#install",
)
}

if lock == nil {
Expand Down
8 changes: 2 additions & 6 deletions internal/plugins/lock/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@ import (
// UpdateLock - update and write out a new lock file
func UpdateLock(manifest *manifestType.Manifest, newLockFile *Lock) error {
// First load the lock file
lockFile, err := FindAndLoadLock()
if err != nil {
// Handle if there is no lock file
return err
}
lockFile := FindAndLoadLock()

err = updateLock(manifest, lockFile, newLockFile)
err := updateLock(manifest, lockFile, newLockFile)

return err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/tasks/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func Delete(c *cli.Context) {
fmt.Sprintf(
"Add the path to the source template file you want to generate like: `kombustion upsert template.yaml`.",
),
"",
"https://www.kombustion.io/api/manifest/",
)
}

Expand Down
5 changes: 2 additions & 3 deletions internal/tasks/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import (
printer "github.com/KablamoOSS/go-cli-printer"
"github.com/KablamoOSS/kombustion/internal/cloudformation"
"github.com/KablamoOSS/kombustion/internal/cloudformation/tasks"
"github.com/urfave/cli"
"github.com/KablamoOSS/kombustion/internal/manifest"

"github.com/urfave/cli"
)

// PrintEvents outputs the events of a stack
Expand Down Expand Up @@ -41,7 +40,7 @@ func PrintEvents(c *cli.Context) {
fmt.Sprintf(
"Add the path to the source template file, or provide use --stack-name",
),
"",
"https://www.kombustion.io/api/cli/#stacks",
)
}

Expand Down
30 changes: 6 additions & 24 deletions internal/tasks/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,33 +40,15 @@ func Generate(c *cli.Context) {
fmt.Sprintf(
"Add the path to the source template file you want to generate like: `kombustion generate template.yaml`.",
),
"",
"https://www.kombustion.io/api/cli/#generate",
)
}

paramMap := cloudformation.GetParamMap(c)

lockFile, err := lock.FindAndLoadLock()
if err != nil {
printer.Fatal(
err,
fmt.Sprintf(
"kombustion.lock may need to be rebuilt",
),
"",
)
}
lockFile := lock.FindAndLoadLock()

manifestFile := manifest.FindAndLoadManifest()
if err != nil {
printer.Fatal(
err,
fmt.Sprintf(
"kombustion.yaml may need to be rebuilt",
),
"",
)
}

// load all plugins
loadedPlugins := plugins.LoadPlugins(manifestFile, lockFile)
Expand All @@ -81,10 +63,10 @@ func Generate(c *cli.Context) {

printer.Progress("Generating template")
tasks.GenerateTemplate(cloudformation.GenerateParams{
Filename: fileName,
Env: c.String("env"),
Filename: fileName,
Env: c.String("env"),
GenerateDefaultOutputs: c.Bool("generate-default-outputs"),
ParamMap: paramMap,
Plugins: loadedPlugins,
ParamMap: paramMap,
Plugins: loadedPlugins,
})
}
Loading

0 comments on commit 4216544

Please sign in to comment.