mirror of
https://github.com/davidallendj/magellan.git
synced 2025-12-20 03:27:03 -07:00
Improved Error handling without panics
This commit is contained in:
parent
3386690f17
commit
fdc574f5f2
2 changed files with 9 additions and 1 deletions
|
|
@ -3,6 +3,7 @@ package cmd
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
"github.com/OpenCHAMI/magellan/pkg/crawler"
|
"github.com/OpenCHAMI/magellan/pkg/crawler"
|
||||||
|
|
@ -31,7 +32,7 @@ var crawlCmd = &cobra.Command{
|
||||||
Insecure: cmd.Flag("insecure").Value.String() == "true",
|
Insecure: cmd.Flag("insecure").Value.String() == "true",
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
log.Fatalf("Error crawling BMC: %v", err)
|
||||||
}
|
}
|
||||||
// Marshal the inventory details to JSON
|
// Marshal the inventory details to JSON
|
||||||
jsonData, err := json.MarshalIndent(systems, "", " ")
|
jsonData, err := json.MarshalIndent(systems, "", " ")
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package crawler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
"github.com/stmcginnis/gofish"
|
"github.com/stmcginnis/gofish"
|
||||||
|
|
@ -56,6 +57,12 @@ func CrawlBMC(config CrawlerConfig) ([]InventoryDetail, error) {
|
||||||
BasicAuth: true,
|
BasicAuth: true,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if strings.HasPrefix(err.Error(), "404:") {
|
||||||
|
err = fmt.Errorf("no ServiceRoot found. This is probably not a BMC: %s", config.URI)
|
||||||
|
}
|
||||||
|
if strings.HasPrefix(err.Error(), "401:") {
|
||||||
|
err = fmt.Errorf("authentication failed. Check your username and password: %s", config.URI)
|
||||||
|
}
|
||||||
event := log.Error()
|
event := log.Error()
|
||||||
event.Err(err)
|
event.Err(err)
|
||||||
event.Msg("failed to connect to BMC")
|
event.Msg("failed to connect to BMC")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue