fix some error handling
Some checks failed
Declarative Tests / test (push) Waiting to run
Lint / golangci-lint (push) Has been cancelled

This commit is contained in:
Matthew Rich 2024-05-26 02:30:31 -07:00
parent 5f7db0b4d0
commit 39f29fd029
2 changed files with 5 additions and 5 deletions

View File

@ -86,11 +86,11 @@ func LoadSourceURI(uri string) []*resource.Document {
if uri != "" {
ds, err := source.SourceTypes.New(uri)
if err != nil {
log.Fatal(err)
slog.Error("Failed loading document from source", "error", err)
}
extractDocuments, extractErr := ds.ExtractResources(nil)
if extractErr != nil {
log.Fatal(extractErr)
slog.Error("Failed loading resources from source", "error", extractErr)
}
return extractDocuments
}
@ -126,7 +126,7 @@ func ImportSubCommand(cmd *flag.FlagSet, output io.Writer) (err error) {
slog.Info("main.ImportResource", "args", os.Args, "output", GlobalOutput)
outputTarget, err := target.TargetTypes.New(GlobalOutput)
if err != nil {
log.Fatal(err)
slog.Error("Failed opening target", "error", err)
}
defer outputTarget.Close()
@ -140,7 +140,7 @@ func ImportSubCommand(cmd *flag.FlagSet, output io.Writer) (err error) {
if *ImportResource != "" {
slog.Info("ImportResource", "resource", ImportResource)
if addResourceErr := d.AddResource(*ImportResource); addResourceErr != nil {
log.Fatal(addResourceErr)
slog.Error("Failed adding resource", "error", addResourceErr)
}
}

View File

@ -114,7 +114,7 @@ func (d *Declaration) SetURI(uri string) error {
slog.Info("Declaration.SetURI()", "uri", uri, "declaration", d)
d.Attributes = NewResource(uri)
if d.Attributes == nil {
panic("unknown resource")
return ErrUnknownResourceType
}
d.Type = TypeName(d.Attributes.Type())
_,e := d.Attributes.Read(context.Background()) // fix context