From d5b93caacef6d6529e54f66102e174305e0d1566 Mon Sep 17 00:00:00 2001 From: Christoph Hartmann Date: Sat, 27 Jan 2024 11:37:41 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20return=20proper=20error=20when?= =?UTF-8?q?=20no=20provider=20could=20be=20detected?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- providers/providers.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/providers/providers.go b/providers/providers.go index 9658fca0b4..2127dc63aa 100644 --- a/providers/providers.go +++ b/providers/providers.go @@ -285,6 +285,14 @@ func ListAll() ([]*Provider, error) { return res, nil } +type ProviderNotFoundError struct { + lookup ProviderLookup +} + +func (e *ProviderNotFoundError) Error() string { + return "cannot find provider for " + e.lookup.String() +} + // EnsureProvider makes sure that a given provider exists and returns it. // You can supply providers either via: // 1. providerID, which universally identifies it, e.g. "go.mondoo.com/cnquery/v10/providers/os" @@ -319,7 +327,7 @@ func EnsureProvider(search ProviderLookup, autoUpdate bool, existing Providers) if upstream == nil { // we can't find any provider for this connector in our default set // FIXME: This causes a panic in the CLI, we should handle this better - return nil, nil + return nil, &ProviderNotFoundError{lookup: search} } if !autoUpdate {