add error handling
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-10-04 14:55:15 +10:00
parent 8ea1ddd11b
commit 64815f5fa3

20
main.go
View File

@@ -63,6 +63,7 @@ func GenerateAvgVcpusCharts(f *excelize.File, data any, name string) {
err = json.Unmarshal(ryde.Interface().(json.RawMessage), &rydeData)
if err != nil {
fmt.Printf("Error unmarshaling Ryde for %s: %v\n", fieldName, err)
return
}
}
@@ -70,6 +71,7 @@ func GenerateAvgVcpusCharts(f *excelize.File, data any, name string) {
err = json.Unmarshal(wsdc.Interface().(json.RawMessage), &wsdcData)
if err != nil {
fmt.Printf("Error unmarshaling Wsdc for %s: %v\n", fieldName, err)
return
}
}
@@ -103,12 +105,14 @@ func GenerateCharts(f *excelize.File, data any, name string, location string) {
err = json.Unmarshal(rccField.Interface().(json.RawMessage), &rcc)
if err != nil {
fmt.Printf("Error unmarshaling Ryde: %v\n", err)
return
}
}
if len(wsdcField.Interface().(json.RawMessage)) > 0 {
err = json.Unmarshal(wsdcField.Interface().(json.RawMessage), &wsdc)
if err != nil {
fmt.Printf("Error unmarshaling Wsdc: %v\n", err)
return
}
}
@@ -151,7 +155,7 @@ func AvgChart(f *excelize.File, worksheetName string, location string, avgCpuCol
// Sort dates using the custom function
err = sortDates(dataDates)
if err != nil {
fmt.Println("Failed to sort dates:", err)
fmt.Printf("Failed to sort dates for worksheet %s: %s\n", worksheetName, err)
return
}
@@ -232,7 +236,7 @@ func AvgChart(f *excelize.File, worksheetName string, location string, avgCpuCol
Width: 800,
},
}); err != nil {
fmt.Println(err)
fmt.Printf("Error adding chart to workbook %s at location %s: %s\n", worksheetName, location, err)
return
}
}
@@ -248,12 +252,14 @@ func main() {
f := excelize.NewFile()
defer func() {
if err := f.Close(); err != nil {
fmt.Println(err)
fmt.Printf("Error closing excel sheet: %s\n", err)
os.Exit(1)
}
}()
err = f.SetSheetName("Sheet1", "Report")
if err != nil {
log.Fatal(err)
fmt.Printf("Error renaming Sheet1: %s\n", err)
os.Exit(1)
}
// Load the JSON data from file
@@ -266,7 +272,8 @@ func main() {
byteValue, _ := io.ReadAll(file)
var data Input
if err := json.Unmarshal(byteValue, &data); err != nil {
log.Fatal(err)
fmt.Printf("Error reading json input: %s\n", err)
os.Exit(1)
}
// Generate charts into workbook
@@ -277,7 +284,8 @@ func main() {
// Save workbook
if err := f.SaveAs(*outputFile); err != nil {
fmt.Println(err)
fmt.Printf("Error saving excel workbook: %s\n", err)
os.Exit(1)
}
}