-
Notifications
You must be signed in to change notification settings - Fork 166
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
feat(dojo-lang): add warnings for migrations with prints #2316
feat(dojo-lang): add warnings for migrations with prints #2316
Conversation
WalkthroughOhayo, sensei! This change integrates the Changes
Sequence Diagram(s)sequenceDiagram
participant Developer
participant Compiler
participant ContractValidator
participant PathHandler
Developer->>Compiler: Compile contract
activate Compiler
Compiler->>ContractValidator: Validate library functions
activate ContractValidator
ContractValidator-->>Compiler: Return validation results
deactivate ContractValidator
Compiler->>PathHandler: Resolve file paths
activate PathHandler
PathHandler-->>Compiler: Return canonicalized paths
deactivate PathHandler
Compiler-->>Developer: Compile result
deactivate Compiler
Recent review detailsConfiguration used: .coderabbit.yaml Files selected for processing (1)
Files skipped from review as they are similar to previous changes (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add Documentation and Community
|
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.
@jsanchez556 is the error message always containing the print
keyword? I'm not sure of this, would you have some reference/examples?
I initially used this approach before our conversation two days ago. However, I'm now stuck trying to debug a scenario locally where contracts with print statements are being deployed. It seems like I might be doing something wrong, as neither Sozo nor Katana are throwing errors when this occurs. At this point, I'm unsure if the changes need to be made in Katana rather than Sozo. What do you think? Steps I'm taking to try to reproduce the scenario:
|
The thing is that on Katana, it's totally ok to use For this reason I was mentioning that you can't rely on an error message to know if contracts contain print. dojo/crates/dojo-lang/src/compiler.rs Line 367 in 8db91e7
At this point, you may run a check on the source code, if a print statement is found outside of the tests, you can emit a warning. Or you can do it in the |
7ec7c4d
to
c3b7ba7
Compare
@glihm could you please check this PR |
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.
Actionable comments posted: 2
Outside diff range, codebase verification and nitpick comments (1)
bin/sozo/src/commands/build.rs (1)
87-97
: Enhance the warning message for unsupportedThe current warning message informs the user about the presence of
Consider updating the message as follows:
ui.print( "Warning: Some contracts include `print` functions that are not supported on the current network. \ Please locate and remove these functions from your contract files to ensure compatibility. \ You can search for `print` in the expanded source code or the compiled JSON files.", );
e074fe2
to
e56a80f
Compare
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.
Actionable comments posted: 0
Outside diff range, codebase verification and nitpick comments (2)
bin/sozo/src/utils.rs (2)
141-155
: Ohayo, sensei! Enhance error handling for file extensions.Using
unwrap_or_default
for file extensions can lead to unexpected behavior if the extension is missing. Consider using a more robust error handling approach.Here's a suggested refactor:
fn get_files_from_dir(dir: &Utf8PathBuf, extension: &str) -> Vec<PathBuf> { let mut files = Vec::new(); if let Ok(entries) = fs::read_dir(dir) { for entry in entries { if let Ok(path) = entry.map(|e| e.path()) { if path.is_file() { if let Some(ext) = path.extension() { if ext == extension { files.push(path); } } } } } } files }
157-173
: Ohayo, sensei! Enhance error handling for file paths.Using
unwrap_or_default
for file paths can lead to unexpected behavior if the path conversion fails. Consider using a more robust error handling approach.Here's a suggested refactor:
pub fn exists_func_in_contracts(target_dir: &Utf8PathBuf, functions: &[&str]) -> bool { let compiled_contracts = get_files_from_dir(target_dir, "json"); let mut type_exists = false; for contract in compiled_contracts { if let Some(contract_str) = contract.to_str() { if let Ok(file_content) = fs::read_to_string(contract_str) { type_exists = functions .iter() .any(|&func| file_content.contains(&format!("\"{}\"", func))); if type_exists { break; } } } } type_exists }
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.
@jsanchez556 nice work on that! Looking into the Sierra is a very good approach.
This code should work, I'm just wondering about the potential performance running contains
on Sierra files that may be big.
The print
is found under sierra_program_debug_info
, we may restrict the contains to this part.
Also, checking on scarb, they use this function: https://github.com/software-mansion/scarb/blob/b29b842af42df38ee118eaceb0bea88da35dbab4/scarb/src/compiler/compilers/starknet_contract.rs#L414
As we already have the ContractDeclaration
and ContractClass
in memory, it might be more efficient.
WDYT? Could be great if you could give it a try. The scarb function is not public, so we may have to implement a similar logic though.
2a89874
to
c1f9d91
Compare
@glihm I've implemented a similar logic based on scarb. Could you please review it and share your thoughts? |
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.
@jsanchez556 good work!
In the case of Dojo, we can have a simplified version for now, please find the comments below, and if you have any comment / other idea, please don't hesitate!
Thank you again for the work done here.
d6353af
to
99f24a6
Compare
@coderabbitai full review |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2316 +/- ##
==========================================
- Coverage 67.26% 67.24% -0.02%
==========================================
Files 357 357
Lines 46634 46657 +23
==========================================
+ Hits 31367 31376 +9
- Misses 15267 15281 +14 ☔ View full report in Codecov by Sentry. |
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.
Awesome @jsanchez556 thanks for the work done here and your time to contribute! 🚀
Description
Related issue
Tests
Added to documentation?
Checklist
scripts/prettier.sh
,scripts/rust_fmt.sh
,scripts/cairo_fmt.sh
)scripts/clippy.sh
,scripts/docs.sh
)Summary by CodeRabbit
New Features
Bug Fixes