-
Notifications
You must be signed in to change notification settings - Fork 21
[Enhancement] error codes (CF-704) #695
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
Open
mohammedahmed18
wants to merge
11
commits into
main
Choose a base branch
from
enhancement/codeflash-errors
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
35f7738
codeflash errors and codes
mohammedahmed18 13b5284
error message for baseline establishment failure
mohammedahmed18 35598cf
typo
mohammedahmed18 9776836
⚡️ Speed up function `test_confidence_threshold_not_met_error` by 64%…
codeflash-ai[bot] 8890ef5
⚡️ Speed up function `behavioral_test_failure_error` by 107% in PR #6…
codeflash-ai[bot] 239d938
fix tests
mohammedahmed18 baa6e1b
Merge branch 'enhancement/codeflash-errors' into codeflash/optimize-p…
mohammedahmed18 4bd9e25
Merge pull request #697 from codeflash-ai/codeflash/optimize-pr695-20…
mohammedahmed18 46261d1
Merge branch 'enhancement/codeflash-errors' into codeflash/optimize-p…
mohammedahmed18 ca4a194
Merge pull request #696 from codeflash-ai/codeflash/optimize-pr695-20…
mohammedahmed18 479b2da
top level error values
mohammedahmed18 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Empty file.
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
from __future__ import annotations | ||
|
||
from codeflash.code_utils.compat import LF | ||
from codeflash.either import CodeflashError | ||
|
||
_TEST_CONFIDENCE_ERROR = CodeflashError( | ||
"TEST_CONFIDENCE_THRESHOLD_NOT_MET_ERROR", "The threshold for test confidence was not met." | ||
) | ||
|
||
_BEHAVIORAL_TEST_FAILURE_ERROR = CodeflashError( | ||
"BEHAVIORAL_TEST_FAILURE_ERROR", "Failed to establish a baseline for the original code - bevhavioral tests failed." | ||
) | ||
|
||
_COVERAGE_THRESHOLD_NOT_MET_ERROR = CodeflashError( | ||
"COVERAGE_THRESHOLD_NOT_MET_ERROR", "The threshold for test coverage was not met." | ||
) | ||
|
||
_FUNCTION_OPTIMIZATION_ATTEMPTED_ERROR = CodeflashError( | ||
"FUNCTION_OPTIMIZATION_ATTEMPTED_ERROR", "Function optimization previously attempted, skipping." | ||
) | ||
|
||
_TEST_RESULT_DIDNT_MATCH_ERROR = CodeflashError( | ||
"TEST_RESULT_DIDNT_MATCH_ERROR", "Test results did not match the test results of the original code." | ||
) | ||
|
||
|
||
def test_result_didnt_match_error() -> CodeflashError: | ||
return _TEST_RESULT_DIDNT_MATCH_ERROR | ||
|
||
|
||
def function_optimization_attempted_error() -> CodeflashError: | ||
return _FUNCTION_OPTIMIZATION_ATTEMPTED_ERROR | ||
|
||
|
||
def coverage_threshold_not_met_error() -> CodeflashError: | ||
return _COVERAGE_THRESHOLD_NOT_MET_ERROR | ||
|
||
|
||
def test_confidence_threshold_not_met_error() -> CodeflashError: | ||
return _TEST_CONFIDENCE_ERROR | ||
|
||
|
||
def behavioral_test_failure_error() -> CodeflashError: | ||
return _BEHAVIORAL_TEST_FAILURE_ERROR | ||
|
||
|
||
def shell_rc_permission_error(shell_rc_path: str, api_key_line: str) -> CodeflashError: | ||
return CodeflashError( | ||
"SHELL_RC_PERMISSION_ERROR", | ||
f"I tried adding your Codeflash API key to {{shell_rc_path}} - but seems like I don't have permissions to do so.{LF}" | ||
f"You'll need to open it yourself and add the following line:{LF}{LF}{{api_key_line}}{LF}", | ||
**locals(), | ||
) | ||
|
||
|
||
def shell_rc_not_found_error(shell_rc_path: str, api_key_line: str) -> CodeflashError: | ||
return CodeflashError( | ||
"SHELL_RC_NOT_FOUND_ERROR", | ||
f"💡 I went to save your Codeflash API key to {{shell_rc_path}}, but noticed that it doesn't exist.{LF}" | ||
f"To ensure your Codeflash API key is automatically loaded into your environment at startup, you can create {{shell_rc_path}} and add the following line:{LF}" | ||
f"{LF}{{api_key_line}}{LF}", | ||
**locals(), | ||
) | ||
|
||
|
||
def baseline_establishment_failed_error(failure_msg: str) -> CodeflashError: | ||
return CodeflashError( | ||
"BASELINE_ESTABLISHMENT_FAILED_ERROR", | ||
"Failed to establish a baseline for the original code. {failure_msg}", | ||
**locals(), | ||
) | ||
|
||
|
||
def no_tests_generated_error(function_name: str) -> CodeflashError: | ||
return CodeflashError("NO_TESTS_GENERATED_ERROR", "NO TESTS GENERATED for {function_name}", **locals()) | ||
|
||
|
||
def no_optimizations_generated_error(function_name: str) -> CodeflashError: | ||
return CodeflashError( | ||
"NO_OPTIMIZATIONS_GENERATED_ERROR", "NO OPTIMIZATIONS GENERATED for {function_name}", **locals() | ||
) | ||
|
||
|
||
def no_best_optimization_found_error(function_name: str) -> CodeflashError: | ||
return CodeflashError( | ||
"NO_BEST_OPTIMIZATION_FOUND_ERROR", "No best optimizations found for function {function_name}", **locals() | ||
) | ||
|
||
|
||
def code_context_extraction_failed_error(error: str) -> CodeflashError: | ||
return CodeflashError( | ||
"CODE_CONTEXT_EXTRACTION_FAILED_ERROR", "Failed to extract code context. Error: {error}.", **locals() | ||
) |
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the benefit of this abstraction? it's not very pythonic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean the top level error variable
Or the abstraction of the errors in a separate file