Skip to content

Commit

Permalink
tb: require error names in UPPER_SNAKE case instead of UpperCamel
Browse files Browse the repository at this point in the history
The purpose of this task is to unify the way errors are specified in
markup language and in Rust code.

Till now error names were required to be specified in UpperCammel case.
This is more sutable for struct names in Rust and is less suitable for
constant names, which are by Rust convention written in UPPER_SNAKE
case.

The benefit of having the error names specified in UPPER_SNAKE case is
that it becomes more greppable, i.e., when an error is grepped for in a
codebase the results will include the usage of the error constant as
well as the error definition in markup language.

Looking at the roadmap, this will not always be true when VariantTypes
are introduced. However, every variant type will be associated with a
error-kind constant which will be returned in grep results.
  • Loading branch information
r-bk committed Jul 19, 2024
1 parent fbfc8bf commit b78d76f
Show file tree
Hide file tree
Showing 19 changed files with 342 additions and 339 deletions.
2 changes: 1 addition & 1 deletion crates/tighterror-build/src/parser/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ fn check_name(name: &str, desc: &str, case: Case) -> Result<(), TbError> {
}

pub fn check_error_name(name: &str) -> Result<(), TbError> {
check_name(name, "ErrorObject::name", Case::UpperCamel)
check_name(name, "ErrorObject::name", Case::UpperSnake)
}

pub fn check_category_name(name: &str) -> Result<(), TbError> {
Expand Down
6 changes: 3 additions & 3 deletions crates/tighterror-build/src/parser/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub fn spec_from_err_iter(iter: impl IntoIterator<Item = ErrorSpec>) -> Spec {

pub fn spec_from_module(mut module: ModuleSpec) -> Spec {
let err = ErrorSpec {
name: "DummyErr".into(),
name: "DUMMY_ERR".into(),
..Default::default()
};

Expand All @@ -64,7 +64,7 @@ pub fn spec_from_module(mut module: ModuleSpec) -> Spec {

pub fn spec_from_main(main: MainSpec) -> Spec {
let err = ErrorSpec {
name: "DummyErr".into(),
name: "DUMMY_ERR".into(),
..Default::default()
};

Expand All @@ -88,7 +88,7 @@ pub fn spec_from_main(main: MainSpec) -> Spec {

pub fn spec_from_category(mut cat: CategorySpec) -> Spec {
let err = ErrorSpec {
name: "DummyErr".into(),
name: "DUMMY_ERR".into(),
..Default::default()
};
cat.errors = vec![err];
Expand Down
Loading

0 comments on commit b78d76f

Please sign in to comment.