Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak type error handling #12

Merged
merged 4 commits into from
Sep 25, 2024
Merged

Tweak type error handling #12

merged 4 commits into from
Sep 25, 2024

Conversation

seddonym
Copy link
Collaborator

@seddonym seddonym commented Sep 25, 2024

Tweaks the way we handle problematic types passed to bundle.get_translation, relating to fluent variables.

  1. If a variable key is not a string, we raise a TypeError. Variable keys should be hardcoded in an application, so it's helpful to see it crash.
  2. If there is a problem with the passed a variable value , we use the name of the variable in its place. This is consistent with how Django FTL, and is in the spirit of 'something is better than nothing'. Variable values vary at runtime and it's good to be more resilient to problems with these.

@seddonym seddonym marked this pull request as ready for review September 25, 2024 11:22
@seddonym seddonym requested a review from a team as a code owner September 25, 2024 11:22
Copy link

@meshy meshy left a comment

Choose a reason for hiding this comment

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

Some thoughts and suggestions, no blockers. 👍

Copy link

@meshy meshy Sep 25, 2024

Choose a reason for hiding this comment

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

Thought (out of scope): Are we running pre-commit in CI? If not, perhaps we should be.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh interesting, I hadn't thought of that as being standard practice, but maybe it's a good idea. Do we do that on kraken-core?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

(We are running the same things that precommit does in CI, though, such as linting and formatting checks.)

Copy link

Choose a reason for hiding this comment

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

It's not uncommon to use pre-commit to do the running of those tools, especially in smaller projects.

KC does not do that.

(
object(),
34.3,
1_000_000_000_000, # Larger than unsigned long integer.
Copy link

Choose a reason for hiding this comment

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

Suggestion: It looks like ints are unacceptable, regardless of if they're in range. Perhaps we should add that to the test too.

(Perhaps it's just not clear to me why we're testing out-of-range values in this way.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh that's a good point - the out of range thing is only relevant for the variable values. I'll change it.

Comment on lines 72 to 73
34.3,
1_000_000_000_000, # Larger than unsigned long integer.
Copy link

Choose a reason for hiding this comment

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

Similar to the comment above, it might be worth accounting for ints that are in range here too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's covered by the test below, test_selector.

But I just realised that this should say 'signed', not 'unsigned', so thanks for drawing my attention to it!

Comment on lines +91 to +92
if !python_key.is_instance_of::<PyString>() {
return Err(PyTypeError::new_err(format!(
Copy link

Choose a reason for hiding this comment

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

Thought (out of scope): I'm beginning to wonder if we might be able to represent this whole for-loop-context with a match statement? 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, there's certainly room for improvement! I'm still a noob at Rust. 😊

Copy link

Choose a reason for hiding this comment

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

Me too :D

@seddonym seddonym merged commit 9e6877a into main Sep 25, 2024
1 check passed
@seddonym seddonym deleted the tweak-type-error-handling branch September 25, 2024 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants