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

[js] Make error friendly when isOrtFormat is undefined #19958

Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion js/web/lib/onnxjs/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export class Model {
constructor() {}

load(buf: Uint8Array, graphInitializer?: Graph.Initializer, isOrtFormat?: boolean): void {
let onnxError: Error|undefined;
if (!isOrtFormat) {
// isOrtFormat === false || isOrtFormat === undefined
try {
Expand All @@ -25,10 +26,19 @@ export class Model {
if (isOrtFormat !== undefined) {
throw e;
}
onnxError = e;
}
}

this.loadFromOrtFormat(buf, graphInitializer);
try {
this.loadFromOrtFormat(buf, graphInitializer);
} catch (e) {
if (isOrtFormat !== undefined) {
throw e;
}
// Tried both formats and failed (when isOrtFormat === undefined)
throw new Error(`Failed to load model as ONNX format: ${onnxError}\nas ORT format: ${e}`);
}
}

private loadFromOnnxFormat(buf: Uint8Array, graphInitializer?: Graph.Initializer): void {
Expand Down
Loading