Skip to content

Commit

Permalink
Fix error message for mis-formatted version field in manifest.yml (#1904
Browse files Browse the repository at this point in the history
)
  • Loading branch information
sfc-gh-pjafari authored Nov 28, 2024
1 parent 632479d commit 4e59e0d
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/snowflake/cli/_plugins/nativeapp/artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,12 +777,16 @@ def find_version_info_in_manifest_file(
label: Optional[str] = None

version_info = manifest_content.get("version", None)
if version_info:
if name_field in version_info:
if version_info is not None:
if not isinstance(version_info, dict):
raise ClickException(
"Error occurred while reading manifest.yml. Received unexpected version format."
)
if version_info.get(name_field) is not None:
version_name = to_identifier(str(version_info[name_field]))
if patch_field in version_info:
if version_info.get(patch_field) is not None:
patch_number = int(version_info[patch_field])
if label_field in version_info:
if version_info.get(label_field) is not None:
label = str(version_info[label_field])

return VersionInfo(version_name, patch_number, label)
Expand Down
43 changes: 43 additions & 0 deletions tests/nativeapp/test_artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from typing import Dict, Iterable, List, Optional, Union

import pytest
from click import ClickException
from snowflake.cli._plugins.nativeapp.artifacts import (
ArtifactError,
ArtifactPredicate,
Expand All @@ -28,6 +29,7 @@
NotInDeployRootError,
SourceNotFoundError,
TooManyFilesError,
VersionInfo,
build_bundle,
find_events_definitions_in_manifest_file,
find_version_info_in_manifest_file,
Expand All @@ -39,6 +41,7 @@
from snowflake.cli.api.project.util import to_identifier
from yaml import safe_dump

from tests.nativeapp.factories import ManifestFactory
from tests.nativeapp.utils import (
assert_dir_snapshot,
touch,
Expand Down Expand Up @@ -1426,6 +1429,46 @@ def test_find_version_info_in_manifest_file(version_name, patch_name, label):
assert l == label


@pytest.mark.parametrize("version_info", ["some_name", ["li1", "li2"], "", 4])
def test_bad_version_info_in_manifest_file_throws_error(version_info):
manifest_contents = ManifestFactory(version=version_info)

deploy_root_structure = {"manifest.yml": manifest_contents}
with temp_local_dir(deploy_root_structure) as deploy_root:
with pytest.raises(ClickException) as err:
find_version_info_in_manifest_file(deploy_root=deploy_root)
assert (
err.value.message
== "Error occurred while reading manifest.yml. Received unexpected version format."
)


def test_read_empty_version_info_in_manifest_file():
manifest_contents = ManifestFactory(
version={"name": None, "patch": None, "label": None}
)

deploy_root_structure = {"manifest.yml": manifest_contents}
with temp_local_dir(deploy_root_structure) as deploy_root:

version_info = find_version_info_in_manifest_file(deploy_root=deploy_root)
assert version_info == VersionInfo(
version_name=None, patch_number=None, label=None
)


def test_read_empty_version_in_manifest_file():
manifest_contents = ManifestFactory(version=None)

deploy_root_structure = {"manifest.yml": manifest_contents}
with temp_local_dir(deploy_root_structure) as deploy_root:

version_info = find_version_info_in_manifest_file(deploy_root=deploy_root)
assert version_info == VersionInfo(
version_name=None, patch_number=None, label=None
)


@pytest.mark.parametrize(
"configuration_section, expected_output",
[
Expand Down

0 comments on commit 4e59e0d

Please sign in to comment.