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

[RFC] Standardizing Taichi Error Types #3938

Open
lin-hitonami opened this issue Jan 5, 2022 · 4 comments
Open

[RFC] Standardizing Taichi Error Types #3938

lin-hitonami opened this issue Jan 5, 2022 · 4 comments
Labels
discussion Welcome discussion! RFC

Comments

@lin-hitonami
Copy link
Contributor

lin-hitonami commented Jan 5, 2022

Motivation

In the taichi code base, there are too many kinds of error types like KernelDefError, KernelArgError, InvalidOperationError, TaichiSyntaxError, RuntimeError, TypeError, ValueError, and even Exception. Moreover, there is no standard on which error should be raised in which situation. So, we should standardize the error types.

Goals

  • Make rules on when should we use which error type.
  • Let the error types inherit the corresponding python errors.
  • Change the errors in the code base to comply with the rules.

Proposal

  • TaichiCompilationError
    • The base class of all errors generated in the compilation process.
    • Used when an error in the compilation process occurs that does not fit in other errors.
  • TaichiTypeError
    • Inherits TaichiCompilationError and TypeError
    • Used when a type error is detected when performing type checks.
  • TaichiSyntaxError
    • Inherits TaichiCompilationError and SyntaxError
    • Used when encountering a syntax that taichi does not support.
  • TaichiNameError
    • Inherits TaichiCompilationError and NameError
    • Used when taichi encounters a undefined name.
  • TaichiRuntimeError
    • Inherits RuntimeError
    • Used when a compiled taichi program fails to execute.
  • TaichiRuntimeTypeError
    • Inherits TaichiRuntimeError and TypeError
    • Used when the type of an argument does not match the corresponding kernel parameter.
@lin-hitonami lin-hitonami added discussion Welcome discussion! RFC labels Jan 5, 2022
@k-ye
Copy link
Member

k-ye commented Jan 5, 2022

Looks great!

I suggest not to TaichiTypeError inherit from TaichiCompilationError. It is possible to produce a type error at compile time. E.g. your kernel takes in a vec3, but a vec4 is passed in.

@strongoier
Copy link
Contributor

Looks great!

I suggest not to TaichiTypeError inherit from TaichiCompilationError. It is possible to produce a type error at compile time. E.g. your kernel takes in a vec3, but a vec4 is passed in.

I would consider this case as a TaichiRuntimeError because it doesn't belong to the Taichi compilation process. Instead, the situation is that the compiled program fails to execute.

@lin-hitonami
Copy link
Contributor Author

Maybe we can add TaichiRuntimeTypeError that inherits TaichiRuntimeError and TypeError for this case?

@strongoier
Copy link
Contributor

Maybe we can add TaichiRuntimeTypeError that inherits TaichiRuntimeError and TypeError for this case?

Sounds good to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Welcome discussion! RFC
Projects
None yet
Development

No branches or pull requests

3 participants