Skip to content

Conversation

@novaugust
Copy link
Contributor

@novaugust novaugust commented Dec 30, 2025

adds when is_integer(limit) to the Enum.count_until argument errors from #15029, making sure FunctionClauseError is still raised for non integer limits

@davydog187
Copy link
Contributor

IMO FunctionClauseError is internal-facing, and ArgumentError is a better external facing exception for consumers of the API

@zachdaniel
Copy link
Contributor

yeah, I'd prefer a fallback raising an ArgumentError when its not an integer, or a clause at the top matching on non-integers not is_integer raising an ArgumentError

@novaugust
Copy link
Contributor Author

As is, you'll get neither when a map is passed as the second arg eh? Needs an inspect in the error message if that's the intention

@novaugust
Copy link
Contributor Author

IMO FunctionClauseError is internal-facing, and ArgumentError is a better external facing exception for consumers of the API

that's not currently a convention i see in elixir, and to zach's point would involve adding a whole lot of final function clauses and when not is_... to existing ones to become the convention. FunctionClauseError is normal and fine when passed a whacky arg (Enum.count_until([], :whoops), especially since the error includes the patterned heads.

@josevalim
Copy link
Member

We typically don’t raise argument errors when the value is outside the domain of the function. So if you pass a list as count, it should be a function clause error. Plus the type system can infer proper types in those cases, if you accept the argument and then raise, it cannot.

@josevalim josevalim merged commit a077a6e into elixir-lang:main Dec 31, 2025
11 checks passed
@josevalim
Copy link
Member

💚 💙 💜 💛 ❤️

@novaugust novaugust deleted the me/count-until-is-integer branch December 31, 2025 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants