-
Notifications
You must be signed in to change notification settings - Fork 441
[Inference] Improve error handling #1504
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
047646b
narrower error types
SBrandeis 6beab33
update provider-specific code to use the new error types
SBrandeis 92d3421
Update packages/inference/src/providers/hf-inference.ts
SBrandeis 47e7e42
lint + format
SBrandeis ed20d68
format+lint
SBrandeis 5f1ee42
add some docs about errors in the README
SBrandeis df0c580
names
julien-c 9a3240d
one more, will we ever get rid of that old name? 🔫
julien-c 665f449
rename error -> errors
SBrandeis 43b3b92
format+lint
SBrandeis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import type { JsonObject } from "./vendor/type-fest/basic.js"; | ||
|
||
/** | ||
* Base class for all inference-related errors. | ||
*/ | ||
export abstract class HfInferenceError extends Error { | ||
constructor(message: string) { | ||
super(message); | ||
this.name = "HfInferenceError"; | ||
} | ||
} | ||
|
||
export class HfInferenceInputError extends HfInferenceError { | ||
constructor(message: string) { | ||
super(message); | ||
this.name = "InputError"; | ||
} | ||
} | ||
|
||
interface HttpRequest { | ||
url: string; | ||
method: string; | ||
headers?: Record<string, string>; | ||
body?: JsonObject; | ||
} | ||
|
||
interface HttpResponse { | ||
requestId: string; | ||
status: number; | ||
body: JsonObject | string; | ||
} | ||
|
||
abstract class HfInferenceHttpRequestError extends HfInferenceError { | ||
httpRequest: HttpRequest; | ||
httpResponse: HttpResponse; | ||
constructor(message: string, httpRequest: HttpRequest, httpResponse: HttpResponse) { | ||
super(message); | ||
this.httpRequest = { | ||
...httpRequest, | ||
...(httpRequest.headers | ||
? { | ||
headers: { | ||
...httpRequest.headers, | ||
...("Authorization" in httpRequest.headers ? { Authorization: `Bearer [redacted]` } : undefined), | ||
/// redact authentication in the request headers | ||
}, | ||
} | ||
: undefined), | ||
}; | ||
this.httpResponse = httpResponse; | ||
} | ||
} | ||
|
||
/** | ||
* Thrown when the HTTP request to the provider fails, e.g. due to API issues or server errors. | ||
*/ | ||
export class HfInferenceProviderApiError extends HfInferenceHttpRequestError { | ||
constructor(message: string, httpRequest: HttpRequest, httpResponse: HttpResponse) { | ||
super(message, httpRequest, httpResponse); | ||
this.name = "ProviderApiError"; | ||
} | ||
} | ||
|
||
/** | ||
* Thrown when the HTTP request to the hub fails, e.g. due to API issues or server errors. | ||
*/ | ||
export class HfInferenceHubApiError extends HfInferenceHttpRequestError { | ||
constructor(message: string, httpRequest: HttpRequest, httpResponse: HttpResponse) { | ||
super(message, httpRequest, httpResponse); | ||
this.name = "HubApiError"; | ||
} | ||
} | ||
|
||
/** | ||
* Thrown when the inference output returned by the provider is invalid / does not match the expectations | ||
*/ | ||
export class HfInferenceProviderOutputError extends HfInferenceError { | ||
constructor(message: string) { | ||
super(message); | ||
this.name = "ProviderOutputError"; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tiny nit, feel free to completely disregard