Skip to content
Open
Show file tree
Hide file tree
Changes from 5 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
16 changes: 10 additions & 6 deletions charmcraft/application/commands/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -1534,11 +1534,15 @@ def run(self, parsed_args: argparse.Namespace) -> None:
for lib in local_libs_data
]
)
except errors.LibraryError:
raise errors.LibraryError(
message=f"Library {parsed_args.library} not found in Charmhub.",
logpath_report=False,
)
except errors.LibraryError as e:
# If a specific library was requested, use that in the error message
# Otherwise, re-raise the original error which should have details
if parsed_args.library:
raise errors.LibraryError(
message=f"Library {parsed_args.library} not found in Charmhub.",
logpath_report=False,
) from e
raise

# check if something needs to be done
analysis = []
Expand All @@ -1559,7 +1563,7 @@ def run(self, parsed_args: argparse.Namespace) -> None:
break
else:
raise errors.LibraryError(
message=f"Library {parsed_args.library} not found in Charmhub.",
message=f"Library {lib_data.full_name} not found in Charmhub.",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot write tests for this behaviour. Including a spread test.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added tests in commit 026f5c1:

Integration test (test_fetchlib_all_library_not_found):

  • Creates a library with a fake lib_id that doesn't exist in Charmhub
  • Runs fetch-lib without arguments
  • Verifies error message shows charms.nonexistent_charm.v0.nonexistent_lib instead of None

Spread test (store/libraries-not-found):

  • Creates a charm directory with a library using a fake lib_id
  • Runs charmcraft fetch-lib without arguments
  • Verifies error message contains the library name and not "Library None"
  • Tests the actual command-line behavior end-to-end

logpath_report=False,
)
emit.debug(f"Store tip: {tip}")
Expand Down
28 changes: 28 additions & 0 deletions tests/integration/commands/test_store_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,34 @@ def test_fetchlib_store_not_found(
)


@pytest.mark.slow
def test_fetchlib_all_with_not_found(
emitter: craft_cli.pytest_plugin.RecordingEmitter,
new_path: pathlib.Path,
config,
) -> None:
"""When running fetch-lib without args and a library is not found, show the library name."""
# Create a local library file with a fake lib_id that doesn't exist in Charmhub
factory.create_lib_filepath(
"testcharm",
"testlib",
api=0,
patch=1,
lib_id="fakefakefakefakefakefakefakefake",
)

args = argparse.Namespace(library=None, format=None)

with pytest.raises(errors.LibraryError) as exc_info:
FetchLibCommand(config).run(args)

# The error message should contain the actual library name, not "None"
assert "charms.testcharm.v0.testlib" in exc_info.value.args[0]
assert exc_info.value.args[0] == (
"Library charms.testcharm.v0.testlib not found in Charmhub."
)


@pytest.mark.slow
@pytest.mark.parametrize("formatted", [None, "json"])
def test_fetchlib_store_is_old(
Expand Down
Loading