Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Surfaces errors in autoindex configuration#58879

Merged
kritzcreek merged 4 commits into
mainfrom
christoph/fix-autoindex-configuration-nil
Dec 11, 2023
Merged

Surfaces errors in autoindex configuration#58879
kritzcreek merged 4 commits into
mainfrom
christoph/fix-autoindex-configuration-nil

Conversation

@kritzcreek

Copy link
Copy Markdown
Contributor

Fixes #58453

Test plan

Add the vitejs/vite repo to your local sg instance, and view the autoindex configuration page.

After this PR you should see the real error:
Error fetching index configuration: Inference limit: requested content for more than 100 (100) files

instead of a nil pointer exception.

Implementation notes

I added two commits, but the first is completely overridden by the second. In 67ed1c3 I tried to 'interpret' what the code was trying to do in the first place, and return a 'succesful' result even if the evaluation ran into a limit error. That produces very confusing UX though, because now it looks like everything is fine on the configuration page, but there are no build jobs. I think it's better to surface the error in the UI here.

This change leaves things in a bit of an awkward spot. The assignment to limitErr is dead code. I don't think the special handling for limit errors make sense here, and it doesn't work anyway (because somewhere on the code path it's not treated different from other errors). I tried ripping it out, but my go-foo isn't quite there yet. I could either open an issue for the follow-up cleanup, or we could try to pair on it @varungandhi-src WDYT?

Christoph added 2 commits December 11, 2023 09:54
This leads to bad UX, because the user has no idea that something went
wrong, and is just presented with an empty jobs UI
@sourcegraph-bot

sourcegraph-bot commented Dec 11, 2023

Copy link
Copy Markdown
Contributor

Codenotify: Notifying subscribers in CODENOTIFY files for diff ea79dcf...69b096e.

Notify File(s)
@Strum355 internal/codeintel/autoindexing/transport/graphql/root_resolver_configuration_repository.go

Comment on lines +110 to +108
if errors.As(err, &inference.LimitError{}) {
limitErr = err
} else {
return nil, err
}
return nil, err

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This error was meant to be exposed in the GraphQL API as per https://github.com/sourcegraph/sourcegraph/pull/47748 where it was introduced. Removing this assignment here would stop that from working.

@kritzcreek kritzcreek Dec 11, 2023

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, exactly. That's what I was describing in the PR description.

With the code as is it never made it to the GraphQL API, as

result, err := r.autoindexSvc.InferIndexConfiguration(ctx, r.repositoryID, "", "", true)

always returns nil if err is set, even when it is set to LimitErr.

Repeating from the PR description: l wrote 67ed1c3 to show a change that would actually let limitErr make it to the GraphQL API, but the UI doesn't seem to handle that case at all and just produces a bad UX that way.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think the problem needs to be fixed in the frontend where we should pattern match against this error and show a more useful message.

@kritzcreek kritzcreek Dec 11, 2023

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't think the frontend can do much better than show the error as is with this PR:

image

If we actually wanted to make the error message more useful we'd need to include what files the script tried to read that led to this error.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

See these two GraphQL queries:

They're accessing the configuration and parsedConfiguration fields, but not checking the limitError field.

I'm not 100% sure if the idiomatic thing (wrt GraphQL) is to return a non-error with the limit error inside the payload... That seems off, but that's what the end of this function is doing currently. I think we should change that to return limitErr instead of nil.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I've filed https://github.com/sourcegraph/sourcegraph/issues/58885 for improving the UX here.

Comment on lines +111 to +113
resolver.limitErr = err
}
return resolver, err

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@kritzcreek what do you think about this fix instead? The main difference is that we're also setting the limitErr field as defined in the API contract.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I see what you're saying now. This would return partial data and the error from the GraphQL request, right?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah, I think we should at least attempt to respect the API contract. Whether the API is a good one/one we want to tweak/deprecate is a separate question.

@varungandhi-src varungandhi-src left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you cross-check that my suggested fix still works? If so, we can merge the PR.

@kritzcreek kritzcreek merged commit f92302f into main Dec 11, 2023
@kritzcreek kritzcreek deleted the christoph/fix-autoindex-configuration-nil branch December 11, 2023 10:19
vovakulikov pushed a commit that referenced this pull request Dec 12, 2023
Co-authored-by: Varun Gandhi <varun.gandhi@sourcegraph.com>
sourcegraph-release-bot pushed a commit that referenced this pull request Jan 23, 2024
Co-authored-by: Varun Gandhi <varun.gandhi@sourcegraph.com>
(cherry picked from commit f92302f)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Nil pointer exception on index configuration page

3 participants