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

Check for null when using UriResolverExtensionFileReader to read wasm module #1317

Merged
merged 8 commits into from
Oct 11, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
Wrapper,
} from "@polywrap/core-js";
import { IFileReader } from "@polywrap/wasm-js";
import { Result } from "@polywrap/result";
import { Result, ResultErr } from "@polywrap/result";

export class UriResolverExtensionFileReader implements IFileReader {
constructor(
Expand All @@ -18,7 +18,7 @@ export class UriResolverExtensionFileReader implements IFileReader {
) {}

async readFile(filePath: string): Promise<Result<Uint8Array, Error>> {
return await UriResolverInterface.module.getFile(
const result = await UriResolverInterface.module.getFile(
{
invoke: <TData = unknown, TUri extends Uri | string = string>(
options: InvokeOptions<TUri>
Expand All @@ -32,5 +32,10 @@ export class UriResolverExtensionFileReader implements IFileReader {
this.resolverExtensionUri,
combinePaths(this.wrapperUri.path, filePath)
);
if (!result.ok) return result;
if (!result.value) {
return ResultErr(new Error(`File not found at ${filePath}`));
}
return result;
}
}