refactor: surface errors when running reports
This commit is contained in:
1 parent
59316f4a21
commit
26e8524ae5
10 files changed
+42
-33
No files matched your search
@@ -7,14 +7,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// ReportSingleApp is an internal function that displays the app report for one or more apps
|
// ReportSingleApp is an internal function that displays the app report for one or more apps
|
||||||
func ReportSingleApp(appName, infoFlag string) {
|
func ReportSingleApp(appName, infoFlag string) error {
|
||||||
if err := common.VerifyAppName(appName); err != nil {
|
if err := common.VerifyAppName(appName); err != nil {
|
||||||
common.LogFail(err.Error())
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
buildpacks, err := common.PropertyListGet("buildpacks", appName, "buildpacks")
|
buildpacks, err := common.PropertyListGet("buildpacks", appName, "buildpacks")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.LogFail(err.Error())
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
infoFlags := map[string]string{
|
infoFlags := map[string]string{
|
||||||
@@ -23,5 +23,5 @@ func ReportSingleApp(appName, infoFlag string) {
|
|||||||
|
|
||||||
trimPrefix := false
|
trimPrefix := false
|
||||||
uppercaseFirstCharacter := true
|
uppercaseFirstCharacter := true
|
||||||
common.ReportSingleApp("buildpacks", appName, infoFlag, infoFlags, trimPrefix, uppercaseFirstCharacter)
|
return common.ReportSingleApp("buildpacks", appName, infoFlag, infoFlags, trimPrefix, uppercaseFirstCharacter)
|
||||||
}
|
}
|
||||||
@@ -37,7 +37,7 @@ func main() {
|
|||||||
buildpacks.TriggerPostExtract(appName, sourceWorkDir)
|
buildpacks.TriggerPostExtract(appName, sourceWorkDir)
|
||||||
case "report":
|
case "report":
|
||||||
appName := flag.Arg(0)
|
appName := flag.Arg(0)
|
||||||
buildpacks.ReportSingleApp(appName, "")
|
err = buildpacks.ReportSingleApp(appName, "")
|
||||||
default:
|
default:
|
||||||
common.LogFail(fmt.Sprintf("Invalid plugin trigger call: %s", trigger))
|
common.LogFail(fmt.Sprintf("Invalid plugin trigger call: %s", trigger))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ func CommandRemove(args []string, index int) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CommandReport displays a buildpacks report for one or more apps
|
// CommandReport displays a buildpacks report for one or more apps
|
||||||
func CommandReport(appName string, infoFlag string) {
|
func CommandReport(appName string, infoFlag string) error {
|
||||||
if strings.HasPrefix(appName, "--") {
|
if strings.HasPrefix(appName, "--") {
|
||||||
infoFlag = appName
|
infoFlag = appName
|
||||||
appName = ""
|
appName = ""
|
||||||
@@ -126,15 +126,18 @@ func CommandReport(appName string, infoFlag string) {
|
|||||||
if len(appName) == 0 {
|
if len(appName) == 0 {
|
||||||
apps, err := common.DokkuApps()
|
apps, err := common.DokkuApps()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
for _, appName := range apps {
|
for _, appName := range apps {
|
||||||
ReportSingleApp(appName, infoFlag)
|
if err := ReportSingleApp(appName, infoFlag); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
ReportSingleApp(appName, infoFlag)
|
return ReportSingleApp(appName, infoFlag)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CommandSet implements buildpacks:set
|
// CommandSet implements buildpacks:set
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package common
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
@@ -353,7 +354,7 @@ func ReadFirstLine(filename string) (text string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ReportSingleApp is an internal function that displays a report for an app
|
// ReportSingleApp is an internal function that displays a report for an app
|
||||||
func ReportSingleApp(reportType string, appName string, infoFlag string, infoFlags map[string]string, trimPrefix bool, uppercaseFirstCharacter bool) {
|
func ReportSingleApp(reportType string, appName string, infoFlag string, infoFlags map[string]string, trimPrefix bool, uppercaseFirstCharacter bool) error {
|
||||||
flags := []string{}
|
flags := []string{}
|
||||||
for key := range infoFlags {
|
for key := range infoFlags {
|
||||||
flags = append(flags, key)
|
flags = append(flags, key)
|
||||||
@@ -377,14 +378,14 @@ func ReportSingleApp(reportType string, appName string, infoFlag string, infoFla
|
|||||||
|
|
||||||
LogVerbose(fmt.Sprintf("%s%s", RightPad(fmt.Sprintf("%s:", key), 31, " "), v))
|
LogVerbose(fmt.Sprintf("%s%s", RightPad(fmt.Sprintf("%s:", key), 31, " "), v))
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, k := range flags {
|
for _, k := range flags {
|
||||||
if infoFlag == k {
|
if infoFlag == k {
|
||||||
v := infoFlags[k]
|
v := infoFlags[k]
|
||||||
fmt.Println(v)
|
fmt.Println(v)
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -393,7 +394,8 @@ func ReportSingleApp(reportType string, appName string, infoFlag string, infoFla
|
|||||||
for i := 0; i < len(keys); i++ {
|
for i := 0; i < len(keys); i++ {
|
||||||
strkeys[i] = keys[i].String()
|
strkeys[i] = keys[i].String()
|
||||||
}
|
}
|
||||||
LogFail(fmt.Sprintf("Invalid flag passed, valid flags: %s", strings.Join(strkeys, ", ")))
|
|
||||||
|
return errors.New(fmt.Sprintf("Invalid flag passed, valid flags: %s", strings.Join(strkeys, ", ")))
|
||||||
}
|
}
|
||||||
|
|
||||||
// RightPad right-pads the string with pad up to len runes
|
// RightPad right-pads the string with pad up to len runes
|
||||||
|
|||||||
@@ -212,9 +212,9 @@ func ClearNetworkConfig(appName string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ReportSingleApp is an internal function that displays the app report for one or more apps
|
// ReportSingleApp is an internal function that displays the app report for one or more apps
|
||||||
func ReportSingleApp(appName, infoFlag string) {
|
func ReportSingleApp(appName, infoFlag string) error {
|
||||||
if err := common.VerifyAppName(appName); err != nil {
|
if err := common.VerifyAppName(appName); err != nil {
|
||||||
common.LogFail(err.Error())
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
infoFlags := map[string]string{
|
infoFlags := map[string]string{
|
||||||
@@ -226,5 +226,5 @@ func ReportSingleApp(appName, infoFlag string) {
|
|||||||
|
|
||||||
trimPrefix := false
|
trimPrefix := false
|
||||||
uppercaseFirstCharacter := true
|
uppercaseFirstCharacter := true
|
||||||
common.ReportSingleApp("network", appName, infoFlag, infoFlags, trimPrefix, uppercaseFirstCharacter)
|
return common.ReportSingleApp("network", appName, infoFlag, infoFlags, trimPrefix, uppercaseFirstCharacter)
|
||||||
}
|
}
|
||||||
@@ -87,7 +87,7 @@ func main() {
|
|||||||
network.TriggerCorePostDeploy(appName)
|
network.TriggerCorePostDeploy(appName)
|
||||||
case "report":
|
case "report":
|
||||||
appName := flag.Arg(0)
|
appName := flag.Arg(0)
|
||||||
network.ReportSingleApp(appName, "")
|
err = network.ReportSingleApp(appName, "")
|
||||||
default:
|
default:
|
||||||
common.LogFail(fmt.Sprintf("Invalid plugin trigger call: %s", trigger))
|
common.LogFail(fmt.Sprintf("Invalid plugin trigger call: %s", trigger))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ func CommandRebuildall() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CommandReport displays a network report for one or more apps
|
// CommandReport displays a network report for one or more apps
|
||||||
func CommandReport(appName string, infoFlag string) {
|
func CommandReport(appName string, infoFlag string) error {
|
||||||
if strings.HasPrefix(appName, "--") {
|
if strings.HasPrefix(appName, "--") {
|
||||||
infoFlag = appName
|
infoFlag = appName
|
||||||
appName = ""
|
appName = ""
|
||||||
@@ -138,15 +138,17 @@ func CommandReport(appName string, infoFlag string) {
|
|||||||
if len(appName) == 0 {
|
if len(appName) == 0 {
|
||||||
apps, err := common.DokkuApps()
|
apps, err := common.DokkuApps()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
for _, appName := range apps {
|
for _, appName := range apps {
|
||||||
ReportSingleApp(appName, infoFlag)
|
if err := ReportSingleApp(appName, infoFlag); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
ReportSingleApp(appName, infoFlag)
|
return ReportSingleApp(appName, infoFlag)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CommandSet set or clear a network property for an app
|
// CommandSet set or clear a network property for an app
|
||||||
|
|||||||
@@ -18,14 +18,14 @@ type Resource struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ReportSingleApp is an internal function that displays the app report for one or more apps
|
// ReportSingleApp is an internal function that displays the app report for one or more apps
|
||||||
func ReportSingleApp(appName, infoFlag string) {
|
func ReportSingleApp(appName, infoFlag string) error {
|
||||||
if err := common.VerifyAppName(appName); err != nil {
|
if err := common.VerifyAppName(appName); err != nil {
|
||||||
common.LogFail(err.Error())
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
resources, err := common.PropertyGetAll("resource", appName)
|
resources, err := common.PropertyGetAll("resource", appName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
infoFlags := map[string]string{}
|
infoFlags := map[string]string{}
|
||||||
@@ -36,7 +36,7 @@ func ReportSingleApp(appName, infoFlag string) {
|
|||||||
|
|
||||||
trimPrefix := true
|
trimPrefix := true
|
||||||
uppercaseFirstCharacter := false
|
uppercaseFirstCharacter := false
|
||||||
common.ReportSingleApp("resource", appName, infoFlag, infoFlags, trimPrefix, uppercaseFirstCharacter)
|
return common.ReportSingleApp("resource", appName, infoFlag, infoFlags, trimPrefix, uppercaseFirstCharacter)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetResourceValue fetches a single value for a given app/process/request/key combination
|
// GetResourceValue fetches a single value for a given app/process/request/key combination
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ func main() {
|
|||||||
err = resource.TriggerPostDelete(appName)
|
err = resource.TriggerPostDelete(appName)
|
||||||
case "report":
|
case "report":
|
||||||
appName := flag.Arg(0)
|
appName := flag.Arg(0)
|
||||||
resource.ReportSingleApp(appName, "")
|
err = resource.ReportSingleApp(appName, "")
|
||||||
case "resource-get-property":
|
case "resource-get-property":
|
||||||
appName := flag.Arg(0)
|
appName := flag.Arg(0)
|
||||||
processType := flag.Arg(1)
|
processType := flag.Arg(1)
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ func CommandLimitClear(args []string, processType string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CommandReport displays a resource report for one or more apps
|
// CommandReport displays a resource report for one or more apps
|
||||||
func CommandReport(appName string, infoFlag string) {
|
func CommandReport(appName string, infoFlag string) error {
|
||||||
if strings.HasPrefix(appName, "--") {
|
if strings.HasPrefix(appName, "--") {
|
||||||
infoFlag = appName
|
infoFlag = appName
|
||||||
appName = ""
|
appName = ""
|
||||||
@@ -38,15 +38,17 @@ func CommandReport(appName string, infoFlag string) {
|
|||||||
if len(appName) == 0 {
|
if len(appName) == 0 {
|
||||||
apps, err := common.DokkuApps()
|
apps, err := common.DokkuApps()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
for _, appName := range apps {
|
for _, appName := range apps {
|
||||||
ReportSingleApp(appName, infoFlag)
|
if err := ReportSingleApp(appName, infoFlag); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
ReportSingleApp(appName, infoFlag)
|
return ReportSingleApp(appName, infoFlag)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CommandReserve implements resource:reserve
|
// CommandReserve implements resource:reserve
|
||||||
|
|||||||
Reference in new issue
Block a user