Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: infrahubctl should display a proper message when files have a non utf-8 encoding #102

Closed
wvandeun opened this issue Oct 22, 2024 · 0 comments · Fixed by #114
Closed
Assignees
Labels
type/bug Something isn't working as expected

Comments

@wvandeun
Copy link
Contributor

Component

Python SDK, infrahubctl

Infrahub SDK version

0.14.1

Current Behavior

When infrahubctl reads a file that is not using UTF-8 encoding you get the following error message.

Error: 'utf-8' codec can't decode byte 0xfe in position 0: invalid start byte
Traceback (most recent call last):
  File "/private/tmp/testing/.venv/lib/python3.9/site-packages/infrahub_sdk/ctl/utils.py", line 79, in async_wrapper
    return await func(*args, **kwargs)
  File "/private/tmp/testing/.venv/lib/python3.9/site-packages/infrahub_sdk/ctl/schema.py", line 156, in load
    schemas_data = load_schemas_from_disk_and_exit(schemas=schemas)
  File "/private/tmp/testing/.venv/lib/python3.9/site-packages/infrahub_sdk/ctl/schema.py", line 55, in
load_schemas_from_disk_and_exit
    schemas_data = load_schemas_from_disk(schemas=schemas)
  File "/private/tmp/testing/.venv/lib/python3.9/site-packages/infrahub_sdk/ctl/schema.py", line 38, in
load_schemas_from_disk
    schema_file.load_content()
  File "/private/tmp/testing/.venv/lib/python3.9/site-packages/infrahub_sdk/yaml.py", line 17, in load_content
    self.content = yaml.safe_load(self.location.read_text())
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/pathlib.py", line
1257, in read_text
    return f.read()
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/codecs.py", line
322, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xfe in position 0: invalid start byte

This happens when you try to load a schema file or when reading an infrahubctl configuration file.

Expected Behavior

We should display a proper error message that explains that the file we are reading is not encoded using UTF-8 and the location/path of the file that we are trying to read.

Steps to Reproduce

  • Create the following schema file, and save it using UTF-16 encoding.
---
version: "1.0"
nodes:
  - name: Node
    namespace: Testing
    attributes:
      - name: name
        kind: Text
        unique: true
        optional: false
  • You can use iconv -f UTF-8 -t UTF-16 schema.yml > schema_new.yml to convert the encoding of the file.\
  • Load the schema
infrahubctl schema load schema_new.yml

Additional Information

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Something isn't working as expected
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants