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

Implement From<serde_json::Error> on OpenAIError enum #324

Open
ozaner opened this issue Jan 24, 2025 · 0 comments · May be fixed by #325
Open

Implement From<serde_json::Error> on OpenAIError enum #324

ozaner opened this issue Jan 24, 2025 · 0 comments · May be fixed by #325

Comments

@ozaner
Copy link

ozaner commented Jan 24, 2025

The OpenAIError type is implemented using the thiserror crate. It implements From<reqwest::Error> via the #[from] present in the Reqwest variant.

#[derive(Debug, thiserror::Error)]
pub enum OpenAIError {
/// Underlying error from reqwest library after an API call was made
#[error("http error: {0}")]
Reqwest(#[from] reqwest::Error),
/// OpenAI returns error object with details of API call failure
#[error("{0}")]
ApiError(ApiError),
/// Error when a response cannot be deserialized into a Rust type
#[error("failed to deserialize api response: {0}")]
JSONDeserialize(serde_json::Error),
/// Error on the client side when saving file to file system
#[error("failed to save file: {0}")]
FileSaveError(String),
/// Error on the client side when reading file from file system
#[error("failed to read file: {0}")]
FileReadError(String),
/// Error on SSE streaming
#[error("stream failed: {0}")]
StreamError(String),
/// Error from client side validation
/// or when builder fails to build request before making API call
#[error("invalid args: {0}")]
InvalidArgument(String),
}

I think that the #[from] attribute should also be present for the JSONDeserialize variant as well.

Having From<serde_json::Error> implemented would allow me to use it as a trait bound for the error type of my own custom Llm trait.

This is addressed by PR #325

@ozaner ozaner changed the title Add #[from] to ApiError and JSONDeserialize variants in OpenAIError enum. Implement From<serde_json::Error> on OpenAIError enum Jan 24, 2025
@ozaner ozaner linked a pull request Jan 24, 2025 that will close this issue
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 a pull request may close this issue.

1 participant