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

Update definition of TypeError to reflect its broader usage #93

Closed
domenic opened this Issue Oct 20, 2015 · 9 comments

Comments

Projects
None yet
4 participants
@domenic
Member

domenic commented Oct 20, 2015

See https://esdiscuss.org/topic/exception-type-for-invalid-operations for background. I'd like to update the definition of TypeError (currently "Indicates the actual type of an operand is different than the expected type.") to something that more accurately explains how it is used as the catch-all fallback error.

Here's some possible wordings. We can wordsmith in this issue thread then I'll do a PR:

  • Indicates that something went wrong, often related to the input to a function.
  • Indicates that something went wrong, often related to the input to a function or the conditions under which it was called.
  • Indicates that the wrong kind of thing was directly or indirectly passed to a function.
  • Indicates the actual type of an operand is different than the expected type. Also used as a generic "fallback" type of error in situations when other more specific types are not appropriate.
@ljharb

This comment has been minimized.

Show comment
Hide comment
@ljharb

ljharb Oct 20, 2015

Member

I've never understood the reasons why the spec doesn't include more specific error types that everybody can leverage. Would that not be a better approach than explicitly encouraging TypeError be used in a generic fashion?

Member

ljharb commented Oct 20, 2015

I've never understood the reasons why the spec doesn't include more specific error types that everybody can leverage. Would that not be a better approach than explicitly encouraging TypeError be used in a generic fashion?

@domenic

This comment has been minimized.

Show comment
Hide comment
@domenic

domenic Oct 20, 2015

Member

@ljharb did you read the linked thread? It goes through that in some detail.

Regardless, the fact remains that TypeError is used for a lot more cases, so we should update its description to match.

Member

domenic commented Oct 20, 2015

@ljharb did you read the linked thread? It goes through that in some detail.

Regardless, the fact remains that TypeError is used for a lot more cases, so we should update its description to match.

@ljharb

This comment has been minimized.

Show comment
Hide comment
@ljharb

ljharb Oct 20, 2015

Member

I didn't yet - i will, thanks. Fair point - whether it's overused or not, it's still used, so your original point is totes valid

Member

ljharb commented Oct 20, 2015

I didn't yet - i will, thanks. Fair point - whether it's overused or not, it's still used, so your original point is totes valid

@bterlson

This comment has been minimized.

Show comment
Hide comment
@bterlson

bterlson Oct 20, 2015

Member

I don't really love any of the proposals - too wordy without giving solid guidance. How about:

Indicates that an invalid operation has occurred.

"Invalid operation" is synonymous with the current definition if one uses a very loose definition of type. So I think this is really just a clarification. I think covers both all current usages in the spec as well as the "writing to closed stream" scenario and general incorrect usage errors.

Member

bterlson commented Oct 20, 2015

I don't really love any of the proposals - too wordy without giving solid guidance. How about:

Indicates that an invalid operation has occurred.

"Invalid operation" is synonymous with the current definition if one uses a very loose definition of type. So I think this is really just a clarification. I think covers both all current usages in the spec as well as the "writing to closed stream" scenario and general incorrect usage errors.

@allenwb

This comment has been minimized.

Show comment
Hide comment
@allenwb

allenwb Oct 20, 2015

Member

One purpose of that description is to provide guidance as to when it should be chosen. In particular, when TypeError be used instead of RangeError . From that perspective how about:

Indicates an operation could not be performed because the wrong kind of information was passed to it.

Member

allenwb commented Oct 20, 2015

One purpose of that description is to provide guidance as to when it should be chosen. In particular, when TypeError be used instead of RangeError . From that perspective how about:

Indicates an operation could not be performed because the wrong kind of information was passed to it.

@bterlson

This comment has been minimized.

Show comment
Hide comment
@bterlson

bterlson Oct 20, 2015

Member

"Indicates an operation could not be performed" seems identical to "Indicates that an invalid operation has occurred" and I'm ok with either (but lead toward the latter as it matches the tense of existing definitions). You suggest further adding the notion that type error should be used in cases where "passing" is involved, but to me that seems superfluous and potentially confusing - if I had an API that didn't take any input at all, checked some global flag, and threw an error if its true, such an API should probably use a TypeError.

Member

bterlson commented Oct 20, 2015

"Indicates an operation could not be performed" seems identical to "Indicates that an invalid operation has occurred" and I'm ok with either (but lead toward the latter as it matches the tense of existing definitions). You suggest further adding the notion that type error should be used in cases where "passing" is involved, but to me that seems superfluous and potentially confusing - if I had an API that didn't take any input at all, checked some global flag, and threw an error if its true, such an API should probably use a TypeError.

@allenwb

This comment has been minimized.

Show comment
Hide comment
@allenwb

allenwb Oct 21, 2015

Member

Invalid operation, to me, suggests something more akin to "non-existent operation" as opposed to an operation that could not be completed ("performed') because it was asked to operate upon the wrong kind of data. By "passed" I didn't necessary mean via function parameters, I meant any data that the operation needs to access or use so that includes global flags.

But, perhaps the answer is "TypeError is used to indicate an unsuccessful operation when none of the other NativeError objects are an appropriate indication of the failure cause."

Member

allenwb commented Oct 21, 2015

Invalid operation, to me, suggests something more akin to "non-existent operation" as opposed to an operation that could not be completed ("performed') because it was asked to operate upon the wrong kind of data. By "passed" I didn't necessary mean via function parameters, I meant any data that the operation needs to access or use so that includes global flags.

But, perhaps the answer is "TypeError is used to indicate an unsuccessful operation when none of the other NativeError objects are an appropriate indication of the failure cause."

@domenic

This comment has been minimized.

Show comment
Hide comment
@domenic

domenic Oct 21, 2015

Member

TypeError is used to indicate an unsuccessful operation when none of the other NativeError objects are an appropriate indication of the failure cause.

I like this. I was trying to get at it with my

Indicates that something went wrong, often related to the input to a function.

and

Indicates the actual type of an operand is different than the expected type. Also used as a generic "fallback" type of error in situations when other more specific types are not appropriate.

Member

domenic commented Oct 21, 2015

TypeError is used to indicate an unsuccessful operation when none of the other NativeError objects are an appropriate indication of the failure cause.

I like this. I was trying to get at it with my

Indicates that something went wrong, often related to the input to a function.

and

Indicates the actual type of an operand is different than the expected type. Also used as a generic "fallback" type of error in situations when other more specific types are not appropriate.

@bterlson

This comment has been minimized.

Show comment
Hide comment
@bterlson

bterlson Oct 21, 2015

Member

👍 to @allenwb's prose.

Member

bterlson commented Oct 21, 2015

👍 to @allenwb's prose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment