diff --git a/nix-js/runtime-ts/src/helpers.ts b/nix-js/runtime-ts/src/helpers.ts index b6e8807..fca9d92 100644 --- a/nix-js/runtime-ts/src/helpers.ts +++ b/nix-js/runtime-ts/src/helpers.ts @@ -242,17 +242,20 @@ export const selectWithDefault = ( } }; -function selectWithDefault_impl(obj: NixValue, attrpath: NixValue[], default_val: NixValue): NixValue { - let attrs = forceAttrs(obj); +function selectWithDefault_impl(obj: NixValue, attrpath: NixValue[], defaultVal: NixValue): NixValue { + let attrs = force(obj); + if (!isAttrs(attrs)) { + return defaultVal; + } for (const attr of attrpath.slice(0, -1)) { const key = forceStringValue(attr); if (!(key in attrs)) { - return default_val; + return defaultVal; } const cur = force(attrs[key]); if (!isAttrs(cur)) { - return default_val; + return defaultVal; } attrs = cur; } @@ -261,7 +264,7 @@ function selectWithDefault_impl(obj: NixValue, attrpath: NixValue[], default_val if (last in attrs) { return attrs[last]; } - return default_val; + return defaultVal; } export const hasAttr = (obj: NixValue, attrpath: NixValue[]): NixBool => {