Skip to content

Commit 9f86245

Browse files
committed
fix: avoid crash in symlink_package rule
When a target does not have any in the provider, the rule would crash with an index out of range error. This change adds a check to ensure the list is not empty before trying to access its elements, preventing the crash. ``` ERROR: ../2fa837e4c5ce941f68b762e5f8e7dc4d/external/rules_angular~/BUILD.bazel:8:16: in symlink_package rule @@rules_angular~//:node_modules/typescript: Traceback (most recent call last): File "../2fa837e4c5ce941f68b762e5f8e7dc4d/external/rules_angular~/src/private/symlink_package.bzl", line 22, column 63, in _symlink_impl store_info = src[JsInfo].npm_package_store_infos.to_list()[0] Error: index out of range (index is 0, but sequence has 0 elements) ERROR: ../2fa837e4c5ce941f68b762e5f8e7dc4d/external/rules_angular~/BUILD.bazel:8:16: Analysis of target '@@rules_angular~//:node_modules/typescript' failed ERROR: Analysis of target '//packages/angular/ssr/schematics:ssr_schematics_test_lib_strict_deps_test' failed; build aborted: Analysis failed INFO: Elapsed time: 10.270s, Critical Path: 0.02s INFO: 1 process: 1 internal. ERROR: Build did NOT complete successfully ```
1 parent f568493 commit 9f86245

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

src/private/symlink_package.bzl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ def manifest_path(ctx, file):
1818

1919
def _symlink_impl(ctx):
2020
src = ctx.attr.src
21-
22-
store_info = src[JsInfo].npm_package_store_infos.to_list()[0]
23-
src_dir = store_info.package_store_directory
24-
src_workspace = src.label.workspace_name if src.label.workspace_name != "" else ctx.workspace_name
21+
infos = src[JsInfo].npm_package_store_infos.to_list()
22+
if len(infos) == 0:
23+
src_dir = src[JsInfo].npm_sources.to_list()[0]
24+
else:
25+
src_dir = infos[0].package_store_directory
2526

2627
destination = ctx.actions.declare_symlink(ctx.attr.name)
2728
destination_build = ctx.actions.declare_symlink(

0 commit comments

Comments
 (0)