-
Notifications
You must be signed in to change notification settings - Fork 176
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
add missing contract tag in logs #2551
Conversation
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 and nitpick comments (6)
crates/sozo/ops/src/migration/migrate.rs (6)
Line range hint
1060-1064
: Clarify Handling When Class Hashes MatchOhayo, sensei! In the
get_contract_operation_name
function, when thecurrent_class_hash
equalscontract.diff.local_class_hash
, the code currently returns"{}: Already Deployed"
. To enhance clarity, consider explicitly handling the case where the class hashes match, indicating that the contract is already up-to-date.Consider modifying the match arms to explicitly handle the matching class hash:
match provider.get_class_hash_at(BlockId::Tag(BlockTag::Pending), contract_address).await { Ok(current_class_hash) if current_class_hash != contract.diff.local_class_hash => { format!("{}: Upgrade", contract.diff.tag) + } + Ok(current_class_hash) if current_class_hash == contract.diff.local_class_hash => { + format!("{}: Already Up-to-Date", contract.diff.tag) } Err(ProviderError::StarknetError(StarknetError::ContractNotFound)) => { format!("{}: Deploy", contract.diff.tag) - } - Ok(_) => format!("{}: Already Deployed", contract.diff.tag), + } + Err(_) => format!("{}: Deploy", contract.diff.tag), }
Line range hint
541-600
: Refactor Asynchronous Task Distribution for ReadabilityOhayo, sensei! The
register_dojo_models_with_declarers
function involves complex asynchronous task distribution among declarers. The nested loops and HashMap usage make the code a bit intricate. Refactoring this section could improve readability and maintainability.Consider the following refactoring suggestions:
- Extract Functions: Break down the task distribution and result handling into separate helper functions.
- Use Concise Iterators: Utilize Rust's iterator methods like
enumerate()
andmap()
for cleaner loops.- Simplify Async Logic: Consider using
try_join_all
directly with the tasks to manage asynchronous execution.
Line range hint
1278-1285
: Ensure Metadata Upload Errors are Handled ProperlyOhayo, sensei! In the
upload_metadata
function, when uploading IPFS artifacts, errors are caught and printed, but the process continues. This might lead to incomplete metadata registration without clear failure signaling.Consider handling errors more robustly:
- If an upload fails, decide whether to halt the process or collect all failures and report them at the end.
- Ensure that the
resources
vector accurately reflects only the successfully uploaded metadata.
Line range hint
408-452
: Handle Artifact Errors with Specific InformationOhayo, sensei! In the
register_dojo_models
function, when handlingArtifactError
, the error message recommends runningsozo clean
andsozo build
. Providing more context about the error can help users resolve issues faster.Enhance the error message with specific details:
-anyhow!( - "Discrepancy detected in {name}.\nUse `sozo clean` to clean your project.\n - Then, rebuild your project with `sozo build`." -) +anyhow!( + "Discrepancy detected in {name}: {error}.\nPlease run `sozo clean` to clean your project, \ +then rebuild with `sozo build` to resolve the issue." +)
Line range hint
279-288
: Improve Error Messages in Contract DeploymentOhayo, sensei! In the
deploy_contract
function, when deployment fails, the error message could provide more actionable information.Consider including the contract ID and more details in the error message:
Err(e) => { ui.verbose(format!("{e:?}")); - Err(anyhow!("Failed to migrate {contract_id}: {e}")) + Err(anyhow!("Failed to deploy contract '{contract_id}': {e}. Please check the contract configuration and try again.")) }
Line range hint
151-168
: Avoid Duplicate Code in Contract Registration FunctionsOhayo, sensei! The
register_dojo_models_with_declarers
andregister_dojo_contracts_declarers
functions have similar logic to their counterparts without declarers.To follow the DRY (Don't Repeat Yourself) principle, consider refactoring:
- Abstract common logic into shared helper functions.
- Use generics or traits if necessary to handle different types.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (1)
- crates/sozo/ops/src/migration/migrate.rs (1 hunks)
🧰 Additional context used
🔇 Additional comments (2)
crates/sozo/ops/src/migration/migrate.rs (2)
Line range hint
608-635
: Optimize Namespace RegistrationOhayo, sensei! In the
register_namespaces
function, fetching and checking each namespace individually could be optimized.[performance]
Consider batching the resource checks to reduce the number of asynchronous calls:
- Fetch all namespace resources in one batch call if the API supports it.
- Filter out registered namespaces more efficiently to minimize the number of iterations.
Line range hint
240-257
: Check for Missing Namespace RegistrationOhayo, sensei! Before registering models and contracts, ensure that all required namespaces have been registered to prevent potential deployment issues.
Run the following script to verify namespace registration:
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2551 +/- ##
=======================================
Coverage 69.55% 69.55%
=======================================
Files 388 388
Lines 49964 49964
=======================================
Hits 34750 34750
Misses 15214 15214 ☔ View full report in Codecov by Sentry. |
Add missing contract tag in sozo migrate logs
Summary by CodeRabbit
New Features
Bug Fixes
User Interface Improvements
Chores