-
Notifications
You must be signed in to change notification settings - Fork 35
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 noise log when fallthrough from gofail's if block #19
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry for the late response. This PR looks good to me. Could you please rebase it? |
henrybear327
added a commit
to henrybear327/gofail
that referenced
this pull request
Apr 23, 2024
If the code execution flow after the failpoint type conversion doesn't jump to other parts of the code (e.g. return will change the execution flow), the __badTypeXXX will be executed, causing irrelevant error messages to be printed. For example, the following snippet ``` // gofail: var SomeFuncString string // log.Println("SomeFuncString", SomeFuncString) ``` will be generated to the following snippet ``` if vSomeFuncString, __fpErr := __fp_SomeFuncString.Acquire(); __fpErr == nil { SomeFuncString, __fpTypeOK := vSomeFuncString.(string) if !__fpTypeOK { goto __badTypeSomeFuncString } log.Println("SomeFuncString", SomeFuncString) __badTypeSomeFuncString: __fp_SomeFuncString.BadType(vSomeFuncString, "string") } ``` As you can see, because log.println doesn't jump to other parts of the code, after printing the log, we will go to __badTypeSomeFuncString, thus, printing the following message: "SomeFuncString" got value Hello_world of type "string" but expected type "string" Reference: - demo code https://github.com/henrybear327/gofail-perf-fix-demo/tree/issue/val_error
henrybear327
added a commit
to henrybear327/gofail
that referenced
this pull request
Apr 23, 2024
due to the source repo being deleted by the author, I can only reproduce the commits again) If the code execution flow after the failpoint type conversion doesn't jump to other parts of the code, the `__badType` will be executed, causing irrelevant error messages to be printed. For example, consider the following snippet ```go // gofail: var SomeFuncString string // log.Println("SomeFuncString", SomeFuncString) ``` It will be generated into the following snippet ```go if vSomeFuncString, __fpErr := __fp_SomeFuncString.Acquire(); __fpErr == nil { SomeFuncString, __fpTypeOK := vSomeFuncString.(string) if !__fpTypeOK { goto __badTypeSomeFuncString } log.Println("SomeFuncString", SomeFuncString) __badTypeSomeFuncString: __fp_SomeFuncString.BadType(vSomeFuncString, "string") } ``` As you can see, because `log.println` doesn't jump to other parts of the code, after printing the log, the code will continue to execute `__badTypeSomeFuncString`, thus, printing the following message: `"SomeFuncString" got value Hello_world of type "string" but expected type "string"` The solution is to add a `__nomock` label, in the case of type conversion succeeded, thus the `__badType` label won't be executed. Reference: - demo code https://github.com/henrybear327/gofail-perf-fix-demo/tree/issue/val_error Signed-off-by: Chun-Hung Tseng <[email protected]>
henrybear327
added a commit
to henrybear327/gofail
that referenced
this pull request
May 3, 2024
due to the source repo being deleted by the author, I can only reproduce the commits again) If the code execution flow after the failpoint type conversion doesn't jump to other parts of the code, the `__badType` will be executed, causing irrelevant error messages to be printed. For example, consider the following snippet ```go // gofail: var SomeFuncString string // log.Println("SomeFuncString", SomeFuncString) ``` It will be generated into the following snippet ```go if vSomeFuncString, __fpErr := __fp_SomeFuncString.Acquire(); __fpErr == nil { SomeFuncString, __fpTypeOK := vSomeFuncString.(string) if !__fpTypeOK { goto __badTypeSomeFuncString } log.Println("SomeFuncString", SomeFuncString) __badTypeSomeFuncString: __fp_SomeFuncString.BadType(vSomeFuncString, "string") } ``` As you can see, because `log.println` doesn't jump to other parts of the code, after printing the log, the code will continue to execute `__badTypeSomeFuncString`, thus, printing the following message: `"SomeFuncString" got value Hello_world of type "string" but expected type "string"` The solution is to add a `__nomock` label, in the case of type conversion succeeded, thus the `__badType` label won't be executed. Reference: - demo code https://github.com/henrybear327/gofail-perf-fix-demo/tree/issue/val_error Signed-off-by: Chun-Hung Tseng <[email protected]>
henrybear327
added a commit
to henrybear327/gofail
that referenced
this pull request
May 10, 2024
due to the source repo being deleted by the author, I can only reproduce the commits again) If the code execution flow after the failpoint type conversion doesn't jump to other parts of the code, the `__badType` will be executed, causing irrelevant error messages to be printed. For example, consider the following snippet ```go // gofail: var SomeFuncString string // log.Println("SomeFuncString", SomeFuncString) ``` It will be generated into the following snippet ```go if vSomeFuncString, __fpErr := __fp_SomeFuncString.Acquire(); __fpErr == nil { SomeFuncString, __fpTypeOK := vSomeFuncString.(string) if !__fpTypeOK { goto __badTypeSomeFuncString } log.Println("SomeFuncString", SomeFuncString) __badTypeSomeFuncString: __fp_SomeFuncString.BadType(vSomeFuncString, "string") } ``` As you can see, because `log.println` doesn't jump to other parts of the code, after printing the log, the code will continue to execute `__badTypeSomeFuncString`, thus, printing the following message: `"SomeFuncString" got value Hello_world of type "string" but expected type "string"` The solution is to add a `__nomock` label, in the case of type conversion succeeded, thus the `__badType` label won't be executed. Reference: - demo code https://github.com/henrybear327/gofail-perf-fix-demo/tree/issue/val_error Signed-off-by: Chun-Hung Tseng <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
how to reproduce
what I do
and enable gofail and return
false
byexpect
print 2 and return ok
but got
std log message
and print 2 and return ok
what question
generate code after
gofail enable
will bewhen
beFail
asfalse
, it will continue execute__fp_beFail.BadType(vbeFail, "bool");
event if there are no type error.what I fix
to generate this code: