cloudposse / cloudposse/github-action-atmos-component-updater

script fails when it does not detect the uri of component

Open
#86 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
5
Forks
3
PR merge metrics
No merged PRs in 30d

Description

Found a bug? Maybe our [Slack Community](https://cloudposse.com/slack) can help.

[![Slack Community](https://slack.cloudposse.com/for-the-badge.svg)](https://cloudposse.com/slack)

## Describe the Bug

- The Atmos Component Updater will fail if it encounters a fully-commented out `component.yaml` in the component directory. It attempts to scan and not locate the target URI, causing the entire workflow to fail. Would it be possible to produce a warning instead and continue iterating through the component updates?

## Expected Behavior

- The component updater continues updating and skips the broken configuration

## Steps to Reproduce

- Run the workflow

## Screenshots

```console
Traceback (most recent call last):
File "/github/action/src/main.py", line 127, in
cli_main()
File "/usr/local/lib/python3.10/dist-packages/click/core.py", line 1130, in __call__
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/click/core.py", line 1055, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.10/dist-packages/click/core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.10/dist-packages/click/core.py", line 760, in invoke
return __callback(*args, **kwargs)
File "/github/action/src/main.py", line 122, in cli_main
main(github_api_token, config)
File "/github/action/src/main.py", line 15, in main
component_updater.update()
File "/github/action/src/component_updater.py", line 66, in update
responses.extend(self.__update_terraform_dir(infra_terraform_dir))
File "/github/action/src/component_updater.py", line 85, in __update_terraform_dir
response = self.__update_component(infra_terraform_dir, component_file)
File "/github/action/src/component_updater.py", line 123, in __update_component
original_component = AtmosComponent(self.__config.infra_repo_dir, infra_terraform_dir, component_file)
File "/github/action/src/atmos_component.py", line 24, in __init__
self.__initialize()
File "/github/action/src/atmos_component.py", line 81, in __initialize
(self.__uri_repo, self.__uri_path) = self.__parse_uri()
File "/github/action/src/atmos_component.py", line 112, in __parse_uri
uri = self.__yaml_content.get('spec', {}).get('source', {}).get('uri')
AttributeError: 'NoneType' object has no attribute 'get'
```

## solution

- This would ensure that the application stops early with a clear error message if the YAML file is either syntactically incorrect or doesn’t meet the expected structure, making debugging and maintenance easier.

```python
def __load_yaml_content(self):
try:
data = yaml.load(self.__content, Loader=yaml.FullLoader)
except yaml.YAMLError as err:
logging.error("Failed to parse YAML in %s: %s", self.__component_file, err)
raise ValueError("Invalid YAML format") from err

if not isinstance(data, dict):
raise ValueError("YAML content is not a valid dictionary structure")

return data
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.