Skip to content
This repository has been archived by the owner on Sep 12, 2018. It is now read-only.

Move MentatError away from the top-level crate #805

Merged
merged 20 commits into from
Aug 9, 2018

Conversation

grigoryk
Copy link
Contributor

@grigoryk grigoryk commented Aug 8, 2018

This PR is in preparation for landing some of the work in #563 - specifically, the Pre work which splits transaction-like functionality away from the top-level into its own inner crate.

Pre commits move any trait or type that is necessary to compose an error out of a given crate, and into a "leaf" crate, which use the *-traits naming convention (e.g. db and db-traits). This pattern is similar to how Servo structures their internal inter-dependencies, although at a weaker level (since I'm retrofitting this pattern onto the current world, and going all-in on it would be quite a bit of work!).

This move is needed so that we can use a single Error type in our public API.

Without these changes, the Pre patch above would have to leak a TransactionError into mentat's public API space, which is a subset of the MentatError. If the MentatError is defined in an inner crate, it can now be referenced in other inner crates, in absence of circular dependencies.

This pattern is useful for crates which:

  • tie a lot of internal functionality together
  • are exposed as part of the public API
  • themselves don't introduce new error types

A prime example is the "mentat transaction state manager" (the transaction crate in #563), and the upcoming tolstoy which makes heavy use of the transaction crate.

@grigoryk grigoryk requested a review from ncalexan August 8, 2018 23:48
@grigoryk
Copy link
Contributor Author

grigoryk commented Aug 9, 2018

This introduces a temporary inconsistency in how crates are named - the new crates I've added don't use the "mentat_" prefix. The intention is to remove that prefix entirely, but that will be done once work that depends on this - in #563 - lands, to avoid an even more annoying rebase.

Copy link
Member

@ncalexan ncalexan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great. I expect it to have changed the public API, so please bump the Mentat version (to 0.12.0, and don't forget the version in sdks/android).

I'm surprised that you don't have a src/ directory in *-traits. Is there a reason?

Otherwise, bombs away! Good work.

src/errors.rs Outdated
@@ -72,13 +72,13 @@ pub enum MentatError {
InvalidVocabularyVersion,

#[fail(display = "vocabulary {}/{} already has attribute {}, and the requested definition differs", _0, _1, _2)]
ConflictingAttributeDefinitions(String, ::vocabulary::Version, String, Attribute, Attribute),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In all of these messages, ensure that all of these u32 values are printed with "version {}" so that it's clear what the integer means. So
#[fail(display = "vocabulary {}/version {} already has attribute {}, and the requested definition differs", _0, _1, _2)]

@grigoryk
Copy link
Contributor Author

grigoryk commented Aug 9, 2018

I don't expect the public API to have changed - but it's probably a fair statement that it did in some subtle way, and we currently don't have much in place to ensure that it didn't change. Regarding the lack of src/ in the subcrates, it just seemed a bit neater to me.

@grigoryk grigoryk merged commit db4350a into master Aug 9, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants