Skip to content

Commit

Permalink
handle error when requiring namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
vixalien committed Dec 18, 2023
1 parent 83fc12c commit 4607886
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/bindings/girepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
const { g } = openLib(libName("girepository-1.0", 1), {
g: {
irepository: {
require: $void($pointer, $string, $string, $i32, $pointer),
require: $pointer($pointer, $string, $string, $i32, $buffer),
get_n_infos: $i32($pointer, $string),
get_info: $pointer($pointer, $string, $i32),
find_by_gtype: $pointer($pointer, $i64),
Expand Down
35 changes: 27 additions & 8 deletions src/gi.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,34 @@ export function require(namespace, version) {
return repos.get(key);
}

const repo = new Object();
const error = new BigUint64Array(1);

if (
!g.irepository.require(
null,
namespace,
version,
0, // disable lazy load
error,
)
) {
let message = "Unknown error";

if (error) {
const dataView = new ExtendedDataView(
deref_buf(cast_u64_ptr(error[0]), 16),
);
message = deref_str(cast_u64_ptr(dataView.getBigUint64(8)));
}

const versionString = version ? ` version ${version}` : "";

throw new Error(
`Requiring ${namespace}${versionString} failed: ${message}`,
);
}

g.irepository.require(
null,
namespace,
version,
0, // disable lazy load
null,
);
const repo = new Object();

const nInfos = g.irepository.get_n_infos(null, namespace);

Expand Down

0 comments on commit 4607886

Please sign in to comment.