Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 return proper error when no provider could be detected #3138

Merged
merged 1 commit into from
Jan 29, 2024

Conversation

chris-rock
Copy link
Member

The DetectProvider https://github.com/mondoohq/cnquery/blob/main/providers/runtime.go#L168C1-L178C2 relies on the fact that we either have an error or a proper provider object.

// DetectProvider will try to detect and start the right provider for this
// runtime. Generally recommended when you receive an asset to be scanned,
// but haven't initialized any provider. It will also try to install providers
// if necessary (and enabled)
func (r *Runtime) DetectProvider(asset *inventory.Asset) error {
	provider, err := r.providerForAsset(asset)
	if err != nil {
		return err
	}
	return r.UseProvider(provider.ID)
}

Turns out this was not always the case. EnsureProvider has a case where it returns nil, nil. This changes the logic to make the error explicit https://github.com/mondoohq/cnquery/blob/main/providers/providers.go#L318-L323.

Copy link
Contributor

Test Results

744 tests  ±0   744 ✅ ±0   12s ⏱️ ±0s
 83 suites ±0     0 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit d5b93ca. ± Comparison against base commit c360d7e.

This pull request removes 3 and adds 3 tests. Note that renamed tests count towards both.
go.mondoo.com/cnquery/v10/llx ‑ TestSuccess/2024-01-26_16:23:01.003253734_+0000_UTC_m=+0.008987576
go.mondoo.com/cnquery/v10/llx ‑ TestTruthy/2024-01-26_16:23:01.003253734_+0000_UTC_m=+0.008987576
go.mondoo.com/cnquery/v10/llx ‑ TestTruthy/2024-01-26_16:23:01.003253734_+0000_UTC_m=+0.008987576#01
go.mondoo.com/cnquery/v10/llx ‑ TestSuccess/2024-01-27_15:13:56.544851117_+0000_UTC_m=+0.009805760
go.mondoo.com/cnquery/v10/llx ‑ TestTruthy/2024-01-27_15:13:56.544851117_+0000_UTC_m=+0.009805760
go.mondoo.com/cnquery/v10/llx ‑ TestTruthy/2024-01-27_15:13:56.544851117_+0000_UTC_m=+0.009805760#01

Copy link
Member

@imilchev imilchev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@chris-rock chris-rock merged commit e161f1e into main Jan 29, 2024
12 checks passed
@chris-rock chris-rock deleted the chris-rock/no-provider-error branch January 29, 2024 09:57
@github-actions github-actions bot locked and limited conversation to collaborators Jan 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants