DEVELOPMENT.md
loco doctorLoco contain a few major and "blessed" dependencies, these appear both in an app that was generated at the surface level in their Cargo.toml and in the core Loco framework.
If stale, may require an upgrade as a must.
Example for such dependencies:
sea-orm-cli - while Loco uses SeaORM, it uses the SeaORM CLI to generate entities, and so there may be an incompatibility if SeaORM has a too large breaking change between their CLI (which ships separately) and their framework.axumThis is why we are checking these automatically as part of loco doctor.
We keep minimal version requirements for these. As a maintainer, you can update these minimal versions, only if required in doctor.rs.
Before running tests make sure that:
[ ] redis is running [ ] starters/saas frontend package is built:
$ cd starters/saas/frontend
$ npm i -g pnpm
$ pnpm i && pnpm build
Running all tests should be done with:
$ cargo xtask test
This should write out a fresh DB structure (drops and migrates):
$ cargo loco db reset
And then, the entities generators connect to that newly minted DB, to generate a corresponding entities code:
$ cargo loco db entities
Test your changes
DB/Redis, by executing the command cargo loco doctor --environment test. In case you don't have them, refer to the relevant documentation section for guidance.cargo test on the root to test Loco itselfexamples/demo and run cargo test to test our "driver app" which exercises the framework in various waysstarters-* CI are using a fixed version of Loco and are not seeing your changes yetActually bump version + test and align starters
cargo xtask bump-version and give it the next version. Versions are without v prefix. Example: 0.1.3.cargo xtask bump-version with the same version as before.cargo publish to publish the next Loco version (remember: the starters at this point are pointing to the next version already, so we don't want to push until publish finished)Book keeping
Errors are done with thiserror. We adopt a minimalistic approach to errors.
When possible use from conversions.
#[error(transparent)]
JSON(#[from] serde_json::Error),
When complicated, implement a From trait yourself. This is done to centralize errors into one place and not litter needless map_err code which holds error conversion logic (an exception is Context, see below).
When you know a user might need context, resort to manually shaping the error with extra information. First, define the error:
#[error("cannot parse `{1}`: {0}")]
YAMLFile(#[source] serde_yaml::Error, String),
Then, shape it:
serde_yaml::from_str(&rendered)
.map_err(|err| Error::YAMLFile(err, selected_path.to_string_lossy().to_string()))
In this example, the information about where rendered came from was long lost at the serde_yaml::from_str callsite. Which is why errors were cryptic indicating bad YAML format, but not where it comes from (which file).
In this case, we duplicate the YAML error type, leave one of those for auto conversions with from, where we don't have a file, and create a new specialized error type with the file information: YAMLFile.
CONTRIBUTORS commentSome files contain a special CONTRIBUTORS comment. This comment should
contain context, special notes for that module, and a checklist if needed, so please make sure to follow it.