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

fix: /projects endpoint returning null instead of empty array #140

Merged
merged 7 commits into from
Feb 9, 2022

Conversation

bryphe-coder
Copy link
Contributor

While working on the projects page, I noticed the /projects endpoint would return 'null' instead of an empty array. An empty array would simplify the behavior on the client page.

There were already tests in place for this, but they only validated that the item's length is 0... and it turns out len(nil) is also 0.

So this does a couple things:

  • Updates the empty-project tests to check for NotNil as well
  • Update the project endpoints to return an empty array if no rows are returned
  • Remove the hack in /projects page for populating data, as it is no longer needed

@bryphe-coder bryphe-coder self-assigned this Feb 2, 2022
@codecov
Copy link

codecov bot commented Feb 2, 2022

Codecov Report

Merging #140 (48ecdda) into main (d379767) will increase coverage by 0.09%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #140      +/-   ##
==========================================
+ Coverage   68.15%   68.24%   +0.09%     
==========================================
  Files         111      111              
  Lines        6004     6003       -1     
  Branches       68       67       -1     
==========================================
+ Hits         4092     4097       +5     
+ Misses       1521     1515       -6     
  Partials      391      391              
Flag Coverage Δ
unittest-go-macos-latest 65.99% <ø> (-0.27%) ⬇️
unittest-go-ubuntu-latest 67.69% <ø> (+0.22%) ⬆️
unittest-go-windows-latest 65.99% <ø> (+0.10%) ⬆️
unittest-js 64.76% <0.00%> (+0.09%) ⬆️
Impacted Files Coverage Δ
site/pages/projects/index.tsx 0.00% <0.00%> (ø)
provisionerd/provisionerd.go 68.90% <0.00%> (-0.61%) ⬇️
peer/conn.go 78.20% <0.00%> (+1.02%) ⬆️
peer/channel.go 87.19% <0.00%> (+2.43%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d379767...48ecdda. Read the comment docs.

coderd/projects_test.go Outdated Show resolved Hide resolved
@@ -49,6 +49,10 @@ func (api *api) projects(rw http.ResponseWriter, r *http.Request) {
})
return
}
// Don't return 'null'
if projects == nil {
projects = []database.Project{}
Copy link
Member

Choose a reason for hiding this comment

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

I'd rather us to this inside the sql.ErrNoRows like before, and depend on tests to catch the incorrect behavior.

I'm worried about a developer making a mistake for something else, and this masking the error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like this change is also already in main with #166 🎉

@bryphe-coder
Copy link
Contributor Author

This turns out to be much simpler now since the BE fixes for /projects are in - I think still worth merging though, just to clean-up that TODO in the projects page.

@bryphe-coder bryphe-coder merged commit c44d036 into main Feb 9, 2022
@bryphe-coder bryphe-coder deleted the bryphe/fix/empty-projects-array branch February 9, 2022 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants