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

refactor: Python APIの例外の実体をPyO3側ではなくPythonコード側に置く #778

Open
3 tasks done
qryxip opened this issue Apr 7, 2024 · 0 comments
Open
3 tasks done
Labels

Comments

@qryxip
Copy link
Member

qryxip commented Apr 7, 2024

内容

Python APIにおける例外 (e.g. InferenceFailedError)を、pyo3::create_exception!で宣言するのではなくPythonコード側に書きます。

Pros 良くなる点

  • 現在Python例外はクレート側とpyi側の二箇所で宣言されているが、一箇所にできる

Cons 悪くなる点

実現方法

VOICEVOXのバージョン

N/A

OSの種類/ディストリ/バージョン

  • Windows
  • macOS
  • Linux

その他

ここら辺は文字列指定(py.import("voicevox_core")?.import("…")?)することになるのでtypoを考え、全例外をraiseしてexceptするだけのテストを加えた方がいいかもしれません。
(Java APIも今そうなっているので、Java APIと同時でもいいかも)

let top = match err.kind() {
ErrorKind::NotLoadedOpenjtalkDict => NotLoadedOpenjtalkDictError::new_err(msg),
ErrorKind::GpuSupport => GpuSupportError::new_err(msg),
ErrorKind::OpenZipFile => OpenZipFileError::new_err(msg),
ErrorKind::ReadZipEntry => ReadZipEntryError::new_err(msg),
ErrorKind::ModelAlreadyLoaded => ModelAlreadyLoadedError::new_err(msg),
ErrorKind::StyleAlreadyLoaded => StyleAlreadyLoadedError::new_err(msg),
ErrorKind::InvalidModelData => InvalidModelDataError::new_err(msg),
ErrorKind::GetSupportedDevices => GetSupportedDevicesError::new_err(msg),
ErrorKind::StyleNotFound => StyleNotFoundError::new_err(msg),
ErrorKind::ModelNotFound => ModelNotFoundError::new_err(msg),
ErrorKind::InferenceFailed => InferenceFailedError::new_err(msg),
ErrorKind::ExtractFullContextLabel => ExtractFullContextLabelError::new_err(msg),
ErrorKind::ParseKana => ParseKanaError::new_err(msg),
ErrorKind::LoadUserDict => LoadUserDictError::new_err(msg),
ErrorKind::SaveUserDict => SaveUserDictError::new_err(msg),
ErrorKind::WordNotFound => WordNotFoundError::new_err(msg),
ErrorKind::UseUserDict => UseUserDictError::new_err(msg),
ErrorKind::InvalidWord => InvalidWordError::new_err(msg),
};

@qryxip qryxip added 機能向上 初心者歓迎タスク 初心者にも優しい簡単めなタスク labels Apr 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant