Skip to content

Commit

Permalink
[cli] upgrade errors capitalize letter on declarations, remove unneed…
Browse files Browse the repository at this point in the history
…ed format var = var (#21001)

## Description 

- capitalize letter on declarations and notes
- remove unneeded var = var

## Test plan 

snapshots

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] gRPC:
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
  • Loading branch information
jordanjennings-mysten authored Jan 29, 2025
1 parent cc1bf95 commit cfae4ac
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
source: crates/sui/src/unit_tests/upgrade_compatibility_tests.rs
source: crates/sui/src/upgrade_compatibility/../unit_tests/upgrade_compatibility_tests.rs
expression: normalize_path(err.to_string())
---
error[Compatibility E01007]: missing declaration
Expand All @@ -8,26 +8,26 @@ error[Compatibility E01007]: missing declaration
4module upgrades::upgrades {
^^^^^^^^ enum 'EnumToRemove' is missing
= enums cannot be removed or changed during an 'additive' or 'dependency only' upgrade.
= add missing enum 'EnumToRemove' back to the module 'upgrades'.
= Enums cannot be removed or changed during an 'additive' or 'dependency only' upgrade.
= Add missing enum 'EnumToRemove' back to the module 'upgrades'.

error[Compatibility E01007]: missing declaration
┌─ /fixtures/upgrade_errors/additive_errors_v2/sources/UpgradeErrors.move:4:18
4module upgrades::upgrades {
^^^^^^^^ function 'function_to_remove' is missing
= functions cannot be removed or changed during an 'additive' or 'dependency only' upgrade.
= add missing function 'function_to_remove' back to the module 'upgrades'.
= Functions cannot be removed or changed during an 'additive' or 'dependency only' upgrade.
= Add missing function 'function_to_remove' back to the module 'upgrades'.

error[Compatibility E01007]: missing declaration
┌─ /fixtures/upgrade_errors/additive_errors_v2/sources/UpgradeErrors.move:4:18
4 │ module upgrades::upgrades {
^^^^^^^^ struct 'StructToRemove' is missing
= structs cannot be removed or changed during an 'additive' or 'dependency only' upgrade.
= add missing struct 'StructToRemove' back to the module 'upgrades'.
= Structs cannot be removed or changed during an 'additive' or 'dependency only' upgrade.
= Add missing struct 'StructToRemove' back to the module 'upgrades'.

error[Compatibility E01002]: type mismatch
┌─ /fixtures/upgrade_errors/additive_errors_v2/sources/UpgradeErrors.move:7:9
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ error[Compatibility E01006]: module missing
│ ╰─────────────────^ Package is missing module 'identifier'
= Modules which are part package cannot be removed during an upgrade.
= add missing module 'identifier' back to the package.
= Add missing module 'identifier' back to the package.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
source: crates/sui/src/unit_tests/upgrade_compatibility_tests.rs
source: crates/sui/src/upgrade_compatibility/../unit_tests/upgrade_compatibility_tests.rs
expression: normalize_path(err.to_string())
---
error[Compatibility E01001]: missing public declaration
Expand All @@ -8,17 +8,17 @@ error[Compatibility E01001]: missing public declaration
6module upgrades::upgrades {
^^^^^^^^ enum 'EnumToBeRemoved' is missing
= enums are part of a module's public interface and cannot be removed or changed during a 'compatible' upgrade.
= add missing enum 'EnumToBeRemoved' back to the module 'upgrades'.
= Enums are part of a module's public interface and cannot be removed or changed during a 'compatible' upgrade.
= Add missing enum 'EnumToBeRemoved' back to the module 'upgrades'.

error[Compatibility E01001]: missing public declaration
┌─ /fixtures/upgrade_errors/all_v2/sources/UpgradeErrors.move:6:18
6module upgrades::upgrades {
^^^^^^^^ struct 'StructToBeRemoved' is missing
= structs are part of a module's public interface and cannot be removed or changed during a 'compatible' upgrade.
= add missing struct 'StructToBeRemoved' back to the module 'upgrades'.
= Structs are part of a module's public interface and cannot be removed or changed during a 'compatible' upgrade.
= Add missing struct 'StructToBeRemoved' back to the module 'upgrades'.

error[Compatibility E01003]: ability mismatch
┌─ /fixtures/upgrade_errors/all_v2/sources/UpgradeErrors.move:11:19
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ error[Compatibility E01001]: missing public declaration
4module upgrades::enum_ {
^^^^^ enum 'EnumToBeRemoved' is missing
= enums are part of a module's public interface and cannot be removed or changed during a 'compatible' upgrade.
= add missing enum 'EnumToBeRemoved' back to the module 'enum_'.
= Enums are part of a module's public interface and cannot be removed or changed during a 'compatible' upgrade.
= Add missing enum 'EnumToBeRemoved' back to the module 'enum_'.

error[Compatibility E01001]: missing public declaration
┌─ /fixtures/upgrade_errors/declaration_errors_v2/sources/func.move:4:18
4module upgrades::func_ {
^^^^^ public function 'fun_to_be_removed' is missing
= public functions are part of a module's public interface and cannot be removed or changed during a 'compatible' upgrade.
= add missing public function 'fun_to_be_removed' back to the module 'func_'.
= Public functions are part of a module's public interface and cannot be removed or changed during a 'compatible' upgrade.
= Add missing public function 'fun_to_be_removed' back to the module 'func_'.

error[Compatibility E01001]: missing public declaration
┌─ /fixtures/upgrade_errors/declaration_errors_v2/sources/func.move:7:9
Expand All @@ -35,8 +35,8 @@ error[Compatibility E01001]: missing public declaration
4 │ module upgrades::struct_ {
^^^^^^^ struct 'StructToBeRemoved' is missing
= structs are part of a module's public interface and cannot be removed or changed during a 'compatible' upgrade.
= add missing struct 'StructToBeRemoved' back to the module 'struct_'.
= Structs are part of a module's public interface and cannot be removed or changed during a 'compatible' upgrade.
= Add missing struct 'StructToBeRemoved' back to the module 'struct_'.

error[Compatibility E01006]: module missing
┌─ /fixtures/upgrade_errors/declaration_errors_v2/Move.toml:1:1
Expand All @@ -47,7 +47,7 @@ error[Compatibility E01006]: module missing
│ ╰────────────────────────────────────────────────────────────────────────^ Package is missing module 'missing_module'
= Modules which are part package cannot be removed during an upgrade.
= add missing module 'missing_module' back to the package.
= Add missing module 'missing_module' back to the package.


Upgrade failed, this package requires changes to be compatible with the existing package. Its upgrade policy is set to 'compatible'.
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ error[Compatibility E01006]: module missing
│ ╰──────────────────^ Package is missing module 'identifier'
= Modules which are part package cannot be removed during an upgrade.
= add missing module 'identifier' back to the package.
= Add missing module 'identifier' back to the package.
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ error[Compatibility E01006]: module missing
^ Package is missing module 'identifier'
= Modules which are part package cannot be removed during an upgrade.
= add missing module 'identifier' back to the package.
= Add missing module 'identifier' back to the package.
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ error[Compatibility E01006]: module missing
^^^^^^^^^ Package is missing module 'identifier'
= Modules which are part package cannot be removed during an upgrade.
= add missing module 'identifier' back to the package.
= Add missing module 'identifier' back to the package.
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ error[Compatibility E01006]: module missing
│ ╰────────────────────────────────────────────────────────────────────────^ Package is missing module 'identifier'
= Modules which are part package cannot be removed during an upgrade.
= add missing module 'identifier' back to the package.
= Add missing module 'identifier' back to the package.
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ error[Compatibility E01006]: module missing
│ ╰──^ Package is missing module 'identifier'
= Modules which are part package cannot be removed during an upgrade.
= add missing module 'identifier' back to the package.
= Add missing module 'identifier' back to the package.
39 changes: 24 additions & 15 deletions crates/sui/src/upgrade_compatibility/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1031,11 +1031,11 @@ fn missing_module_diag(

diags.add(Diagnostic::new(
Declarations::ModuleMissing,
(loc, format!("Package is missing module '{module_name}'",)),
(loc, format!("Package is missing module '{module_name}'")),
Vec::<(Loc, String)>::new(),
vec![
"Modules which are part package cannot be removed during an upgrade.".to_string(),
format!("add missing module '{module_name}' back to the package."),
format!("Add missing module '{module_name}' back to the package."),
],
));

Expand All @@ -1051,6 +1051,19 @@ fn missing_definition_diag(
) -> Result<Diagnostics, Error> {
let mut diags = Diagnostics::new();

// capitalize the first letter
let capital_declaration_kind = declaration_kind
.chars()
.enumerate()
.map(|(i, c)| {
if i == 0 {
c.to_uppercase().next().unwrap_or(c)
} else {
c
}
})
.collect::<String>();

let module_name = compiled_unit_with_source.unit.name.as_str();
let loc = compiled_unit_with_source
.unit
Expand All @@ -1062,11 +1075,11 @@ fn missing_definition_diag(
Declarations::PublicMissing,
vec![
format!(
"{declaration_kind}s are part of a module's public interface \
"{capital_declaration_kind}s are part of a module's public interface \
and cannot be removed or changed during a 'compatible' upgrade.",
),
format!(
"add missing {declaration_kind} '{identifier_name}' \
"Add missing {declaration_kind} '{identifier_name}' \
back to the module '{module_name}'.",
),
],
Expand All @@ -1076,11 +1089,11 @@ fn missing_definition_diag(
Declarations::Missing,
vec![
format!(
"{declaration_kind}s cannot be removed or changed during an 'additive' or \
"{capital_declaration_kind}s cannot be removed or changed during an 'additive' or \
'dependency only' upgrade.",
),
format!(
"add missing {declaration_kind} '{identifier_name}' \
"Add missing {declaration_kind} '{identifier_name}' \
back to the module '{module_name}'.",
),
],
Expand All @@ -1091,11 +1104,7 @@ fn missing_definition_diag(
code,
(
loc,
format!(
"{declaration_kind} '{identifier_name}' is missing",
declaration_kind = declaration_kind,
identifier_name = identifier_name,
),
format!("{declaration_kind} '{identifier_name}' is missing"),
),
std::iter::empty::<(Loc, String)>(),
[reason_notes].concat(),
Expand Down Expand Up @@ -1129,7 +1138,7 @@ fn function_lost_public(
Declarations::PublicMissing,
(
def_loc,
format!("Function '{function_name}' has lost its public visibility",),
format!("Function '{function_name}' has lost its public visibility"),
),
Vec::<(Loc, String)>::new(),
vec![
Expand Down Expand Up @@ -2040,7 +2049,7 @@ fn enum_variant_missing_diag(
Enums::VariantMismatch,
(
enum_sourcemap.definition_location,
format!("Missing variant '{variant_name}'.",),
format!("Missing variant '{variant_name}'."),
),
Vec::<(Loc, String)>::new(),
vec![
Expand Down Expand Up @@ -2085,7 +2094,7 @@ fn struct_new_diag(
Vec::<(Loc, String)>::new(),
vec![
"Structs cannot be added during a 'dependency only' upgrade.".to_string(),
format!("Remove the struct '{struct_name}' from its module.",),
format!("Remove the struct '{struct_name}' from its module."),
],
));

Expand Down Expand Up @@ -2156,7 +2165,7 @@ fn enum_new_diag(
Vec::<(Loc, String)>::new(),
vec![
"Enums cannot be added during a 'dependency only' upgrade.".to_string(),
format!("Remove the enum '{enum_name}' from its module.",),
format!("Remove the enum '{enum_name}' from its module."),
],
));

Expand Down

0 comments on commit cfae4ac

Please sign in to comment.