Skip to content

Commit

Permalink
v1.0.4: fix json errors
Browse files Browse the repository at this point in the history
  • Loading branch information
PrincessMortix committed Jan 29, 2024
1 parent 58c0cdd commit 596c609
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func main() {
validateLanguage := iso6391.ValidCode(strings.ToLower(*customLanguage))
if !validateLanguage {
if *outputJson {
fmt.Println(errorJson(fmt.Errorf("invalid language code"), "check if the language code is following ISO 639-1 format."))
fmt.Println(errorJson(fmt.Errorf("invalid language code, check if the language code is following ISO 639-1 format")))
os.Exit(1)
}
panic("Invalid language code: " + *customLanguage)
Expand Down Expand Up @@ -182,7 +182,7 @@ func main() {
quality, err := strconv.Atoi(*optionVideoQuality)
if err != nil {
if *outputJson {
fmt.Println(errorJson(err, fmt.Sprintf("expected int on flag -q, got something else: %s", *optionVideoQuality)))
fmt.Println(errorJson(fmt.Errorf("expected int on flag -q, got something else: %s", *optionVideoQuality)))
os.Exit(1)
}
panic(fmt.Errorf("expected int on flag -q, got something else: %s\nError details: %e", *optionVideoQuality, err))
Expand All @@ -192,7 +192,7 @@ func main() {
cobaltRequest, err := gobalt.Run(newSettings)
if err != nil {
if *outputJson {
fmt.Println(errorJson(err, "failed to download the requested media."))
fmt.Println(errorJson(err))
os.Exit(1)
}
panic(err)
Expand Down Expand Up @@ -233,7 +233,7 @@ func checkStatus(api string, returnJson bool) {
check, err := gobalt.CobaltServerInfo(api)
if err != nil {
if returnJson {
fmt.Println(errorJson(err, "failed to contact cobalt server"))
fmt.Println(errorJson(err))
os.Exit(0)
}
fmt.Printf("Failed to contact cobalt server at %s due of the following error %e", api, err)
Expand Down Expand Up @@ -262,13 +262,13 @@ func checkStatus(api string, returnJson bool) {
os.Exit(0)
}

func errorJson(err error, msg string) []byte {
func errorJson(err error) string {
marshalThis := map[string]string{"error": "true",
"message": fmt.Sprintf("%s\nError details: %e", msg, err),
"message": fmt.Sprintf("%s", err),
"url": "",
}
errorInJson, _ := json.Marshal(marshalThis)
return errorInJson
return string(errorInJson)
}

func openInDefaultBrowser(url string) error {
Expand Down

0 comments on commit 596c609

Please sign in to comment.