Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

refactor(types): prefer EmailAddress type to raw strings #196

Merged
merged 1 commit into from Oct 6, 2018

Conversation

philbooth
Copy link
Contributor

The EmailAddress type was only being used in some places, which meant some places that weren't using it had to call validate::email_address manually. This change spreads it throughout most of the project, so that almost everywhere gets to benefit from strong typing.

The only place I decided to leave alone was the provider layer, where some providers have their own EmailAddress struct. I could have aliased it at that layer too, but by that point addresses are just dumb strings anyway so it didn't seem worth it.

(this is an extraction from pb/166-wip because that branch is growing too big)

@mozilla/fxa-devs r?

@philbooth philbooth self-assigned this Oct 4, 2018
@philbooth philbooth requested a review from a team October 4, 2018 18:37
Ok(_) => assert!(false, "DbClient::get_bounces should have failed"),
Err(error) => assert_eq!(format!("{}", error), "400 Bad Request"),
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here we can delete the entire test case because it's not possible to construct an invalid EmailAddress instance to pass to db.get_bounces.

return false;
}
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Again, all this ugly stuff can go now because the validation is already encapsulated inside EmailAddress.

Copy link

@shane-tomlinson shane-tomlinson left a comment

Choose a reason for hiding this comment

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

LGTM, though like other Rust PRs, someone with more rust chops should have a look too.

The EmailAddress type was only being used in some places, which meant
some places that weren't using it had to call `validate::email_address`
manually. This change spreads it throughout most of the project, so
that almost everywhere gets to benefit from strong typing.

The only place I decided to leave it alone was the provider layer, where
some providers have their own `EmailAddress` struct. I could have
aliased it at that layer too, but by that point addresses are just dumb
strings anyway so it didn't seem worth it.
@philbooth philbooth force-pushed the pb/strongly-typed-email-addresses branch from e49fce8 to dc08356 Compare October 5, 2018 13:18
@philbooth
Copy link
Contributor Author

...someone with more rust chops should have a look too.

Merging anyway, because I have a queue of PRs that are partially blocked by this one and it's not clear if anyone else is going to review it or not.

If anyone does have further feedback on this PR, feel free to mention it here and I can address it separately.

@philbooth philbooth merged commit 6a43ce4 into master Oct 6, 2018
@philbooth philbooth deleted the pb/strongly-typed-email-addresses branch October 6, 2018 12:51
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.

None yet

2 participants