Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Fix- Print error messages in pre builder #829

Conversation

brunasilvazup
Copy link
Contributor

@brunasilvazup brunasilvazup commented Jan 15, 2021

Description

This exposes the errors associated with the pre-build, improving the traceability and visibility of the error content.

Some extra improvements were the addition of new mocks and asserts in the tests.

  • In this commit an intermittent test was corrected. -> 972f69b
  • For the names of the mock files I followed the name of the corresponding package

How to verify it

Check the code or clone this pr, make the build and tests errors on build.

image

Changelog

Print error message in pre-builder

Signed-off-by: Bruna Tavares <bruna.silva@zup.com.br>
Signed-off-by: Bruna Tavares <bruna.silva@zup.com.br>
@brunasilvazup brunasilvazup linked an issue Jan 15, 2021 that may be closed by this pull request
@codecov-io
Copy link

codecov-io commented Jan 15, 2021

Codecov Report

Merging #829 (2d9cf86) into master (37ab4d1) will increase coverage by 0.39%.
The diff coverage is 75.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #829      +/-   ##
==========================================
+ Coverage   84.34%   84.73%   +0.39%     
==========================================
  Files         111      111              
  Lines        3857     3859       +2     
==========================================
+ Hits         3253     3270      +17     
+ Misses        432      419      -13     
+ Partials      172      170       -2     
Impacted Files Coverage Δ
pkg/formula/runner.go 0.00% <ø> (ø)
pkg/formula/runner/executor.go 88.23% <0.00%> (+0.73%) ⬆️
pkg/formula/runner/pre_run_builder.go 100.00% <100.00%> (+35.71%) ⬆️

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 37ab4d1...2d9cf86. Read the comment docs.

@brunasilvazup brunasilvazup self-assigned this Jan 18, 2021
@brunasilvazup brunasilvazup added the 🪲 bug Report a bug encountered while operating Ritchie label Jan 18, 2021
@brunasilvazup brunasilvazup changed the title Fix/print error messages in pre builder Fix- Print error messages in pre builder Jan 18, 2021
@brunasilvazup brunasilvazup marked this pull request as ready for review January 18, 2021 19:46
@brunasilvazup brunasilvazup added the ✔️ ready-for-review ready for review label Jan 18, 2021
Comment on lines 385 to 396
type BuilderMock struct {
mock.Mock
}

func (b *BuilderMock) Build(info formula.BuildInfo) error {
args := b.Called(info)
return args.Error(0)
}
func (b *BuilderMock) HasBuilt() bool {
args := b.Called()
return args.Bool(0)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you move this to a dedicated file in mocks with the package name? The mocks.go file is getting large already

func (bm builderMock) HasBuilt() bool {
return *bm.hasBuilt
}

type workspaceListHasherMock struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

should we strive to eliminate this guy?

@@ -47,7 +47,8 @@ func NewPreRunBuilder(
func (b PreRunBuilderManager) Build(relativePath string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you could return an error in this method, it will make your tests easier.

@@ -57,7 +58,8 @@ func (b PreRunBuilderManager) Build(relativePath string) {
}

if err = b.buildOnWorkspace(*workspace, relativePath); err != nil {
fmt.Println(prompt.Red(messageBuildError))
msg := fmt.Sprintf(messageBuildError, err.Error())
fmt.Println(prompt.Red(msg))
Copy link
Contributor

Choose a reason for hiding this comment

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

Here it makes sense for you to return the error, so you prevent its repetition for the user.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will be change this method to return error.

@lucasdittrichzup lucasdittrichzup added waiting reply Waiting for an answer to a comment and removed ✔️ ready-for-review ready for review labels Jan 21, 2021
Signed-off-by: Bruna Tavares <bruna.silva@zup.com.br>
Signed-off-by: Bruna Tavares <bruna.silva@zup.com.br>
Signed-off-by: Bruna Tavares <bruna.silva@zup.com.br>
Signed-off-by: Bruna Tavares <bruna.silva@zup.com.br>
Signed-off-by: Bruna Tavares <bruna.silva@zup.com.br>
@brunasilvazup brunasilvazup added 🚧 WIP Work in Progress and removed waiting reply Waiting for an answer to a comment labels Jan 22, 2021
Signed-off-by: Bruna Tavares <bruna.silva@zup.com.br>
Signed-off-by: Bruna Tavares <bruna.silva@zup.com.br>
…x/print-error-messages-in-pre-builder

Signed-off-by: Bruna Tavares <bruna.silva@zup.com.br>
intermittent

Signed-off-by: Bruna Tavares <bruna.silva@zup.com.br>
Signed-off-by: Bruna Tavares <bruna.silva@zup.com.br>
Signed-off-by: Bruna Tavares <bruna.silva@zup.com.br>
@brunasilvazup brunasilvazup added ✔️ ready-for-review ready for review and removed 🚧 WIP Work in Progress labels Jan 26, 2021
Signed-off-by: Bruna Tavares <bruna.silva@zup.com.br>
…x/print-error-messages-in-pre-builder

Signed-off-by: Bruna Tavares <bruna.silva@zup.com.br>
Copy link
Contributor

@henriquemoraeszup henriquemoraeszup left a comment

Choose a reason for hiding this comment

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

Nice, just a single comment

@@ -287,6 +288,7 @@ func (ar *addRepoCmd) resolveFlags(cmd *cobra.Command) (formula.Repo, error) {
}
}
if !providerValid {
sort.Strings(providers)
Copy link
Contributor

Choose a reason for hiding this comment

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

can you move the sort to inside the ar.repoProviders.List() method? It should not be the responsibility of this command to know that. Also, this way we only need to edit a single point in code, other packages invoking this method could stumble upon the same problem

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I can change, you're right.

@henriquemoraeszup
Copy link
Contributor

henriquemoraeszup commented Jan 26, 2021

Can you add this PR to the pre run test of #788?

Signed-off-by: Bruna Tavares <bruna.silva@zup.com.br>
@brunasilvazup
Copy link
Contributor Author

/merge qa

@ritchie-bot
Copy link
Contributor

ritchie-bot bot commented Jan 26, 2021

🔥 Merge Conflict

…x/print-error-messages-in-pre-builder

Signed-off-by: Bruna Tavares <bruna.silva@zup.com.br>
@brunasilvazup brunasilvazup added 🚧 WIP Work in Progress and removed ✔️ ready-for-review ready for review labels Jan 27, 2021
Signed-off-by: Bruna Tavares <bruna.silva@zup.com.br>
@brunasilvazup brunasilvazup added 🚀 QA and removed 🚧 WIP Work in Progress labels Feb 5, 2021
@ZupIT ZupIT deleted a comment from ritchie-bot bot Feb 5, 2021
@ritchie-bot
Copy link
Contributor

ritchie-bot bot commented Feb 5, 2021

🔥 Merge Conflict

Copy link
Contributor

@kaduartur kaduartur left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

@brunasilvazup brunasilvazup added the ✔️ ready-for-review ready for review label Feb 8, 2021
@brunasilvazup brunasilvazup merged commit ceca367 into ZupIT:master Feb 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🪲 bug Report a bug encountered while operating Ritchie ✔️ ready-for-review ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expose specific error message during build
5 participants