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

v1/internal: refactor GetComposeStatus improve error handling #1324

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mgold1234
Copy link
Contributor

this commit improve error handling and code structure

  • Split GetComposeStatus into smaller, more focused functions
  • Enhance error handling with more specific HTTP status codes *Add dedicated functions for handling different response scenarios
  • Implement parseAndRedactComposeRequest for better separation of concerns
  • Improve code readability and maintainability

Copy link

codecov bot commented Aug 29, 2024

Codecov Report

Attention: Patch coverage is 62.50000% with 15 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/v1/handler.go 62.50% 10 Missing and 5 partials ⚠️
Files with missing lines Coverage Δ
internal/v1/handler.go 64.91% <62.50%> (+0.36%) ⬆️

@mgold1234 mgold1234 force-pushed the imporve_get_compose_status_func branch from 1f37e93 to 17e1d2c Compare September 2, 2024 09:22
Copy link
Contributor

@schuellerf schuellerf left a comment

Choose a reason for hiding this comment

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

While this makes the functions smaller and more readable
it duplicates the number of requests (calling h.getComposeByIdAndOrgId(ctx, composeId) twice now)?
If I'm right - this should be optimized to avoid duplicating the number of external requests

@mgold1234 mgold1234 force-pushed the imporve_get_compose_status_func branch from 17e1d2c to 2c6fd00 Compare September 2, 2024 11:47
Copy link
Contributor

@mvo5 mvo5 left a comment

Choose a reason for hiding this comment

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

Thank you, I'm not familiar with the image-builder codebase so please take my review with a grain of salt. I have some suggestions inline about structure and naming though that are maybe/hopefully helpful :)

internal/v1/handler.go Outdated Show resolved Hide resolved
internal/v1/handler.go Show resolved Hide resolved
internal/v1/handler.go Outdated Show resolved Hide resolved
httpError := echo.NewHTTPError(http.StatusInternalServerError, "Failed querying compose status")
body, err := io.ReadAll(resp.Body)
if err != nil {
ctx.Logger().Errorf("Unable to parse composer's compose response: %v", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this is a pre-existing string but it's a bit misleading, here it's not about parse but about reading.

Copy link
Contributor

Choose a reason for hiding this comment

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

AFAICT this still an open topic, no? Maybe: ctx.Logger().Errorf("Unable to read error response data: %v", err) ?

@mgold1234 mgold1234 force-pushed the imporve_get_compose_status_func branch from 7079a25 to 3852b9e Compare October 1, 2024 11:54
@mgold1234 mgold1234 requested a review from mvo5 October 1, 2024 11:55
@mgold1234 mgold1234 force-pushed the imporve_get_compose_status_func branch 2 times, most recently from ab51f06 to 9b4a036 Compare October 8, 2024 08:35
Copy link
Contributor

@mvo5 mvo5 left a comment

Choose a reason for hiding this comment

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

Thank you and sorry that it took me so long to look at this! This looks nice, some tiny naming/code organisation suggestions inline for your consideration.

internal/v1/handler.go Outdated Show resolved Hide resolved
internal/v1/handler.go Outdated Show resolved Hide resolved
@mgold1234 mgold1234 force-pushed the imporve_get_compose_status_func branch 2 times, most recently from 8e3471f to f55a3b2 Compare October 14, 2024 11:02
@mgold1234 mgold1234 requested a review from mvo5 October 14, 2024 11:02
Copy link

This PR is stale because it has been open 30 days with no activity. Remove "Stale" label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale label Nov 14, 2024
@mgold1234 mgold1234 force-pushed the imporve_get_compose_status_func branch from f55a3b2 to 1c4f770 Compare November 14, 2024 10:35
Copy link
Contributor

@mvo5 mvo5 left a comment

Choose a reason for hiding this comment

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

Thank you for this refactor, I have two small suggestions inline, but if you prefer we could also do them as a followup (but I included a suggested diff so maybe/hopefully it's not much trouble).

internal/v1/handler.go Outdated Show resolved Hide resolved
internal/v1/handler.go Outdated Show resolved Hide resolved
@mgold1234 mgold1234 force-pushed the imporve_get_compose_status_func branch 2 times, most recently from 7aa99c1 to a566c2e Compare November 14, 2024 13:34
internal/v1/handler.go Outdated Show resolved Hide resolved
@mgold1234 mgold1234 force-pushed the imporve_get_compose_status_func branch from a566c2e to d80a189 Compare November 14, 2024 15:03
@github-actions github-actions bot removed the Stale label Nov 15, 2024
@mgold1234 mgold1234 force-pushed the imporve_get_compose_status_func branch from d80a189 to d2b1746 Compare November 26, 2024 11:12
…ode structure

this commit improve error handling and code structure
* Split GetComposeStatus into smaller, more focused functions
* Enhance error handling with more specific HTTP status codes
*Add dedicated functions for handling different response scenarios
* Implement parseAndRedactComposeRequest for better separation of concerns
* Improve code readability and maintainability
@mgold1234 mgold1234 force-pushed the imporve_get_compose_status_func branch from d2b1746 to 36cf450 Compare November 26, 2024 13:29
Copy link
Contributor

@mvo5 mvo5 left a comment

Choose a reason for hiding this comment

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

This is nice, thank you! One tiny comment left but everything else looks very nice now

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.

3 participants