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

An error occurred when executing the push-components task: Cannot read properties of undefined (reading 'length') #130

Open
diaiunese-at-halueio opened this issue Nov 5, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@diaiunese-at-halueio
Copy link

When I want to push a component schema by using the push-components command

Current behavior:

if a component does not contain the fields

 "internal_tags_list": [],

the push-components command will output this error:

- Executing push-components task
- Get presets from component Container
X An error occurred when load components file from api
X An error occurred when executing the push-components task: Cannot read properties of undefined (reading 'length')

And this happens because here

if(internal_tags_list.length > 0) {

it expects internal_tags_list to be present so it checks directly its length, hence the error

Expected behavior:
If internal_tags_list is not present in the the component schema file used as <SOURCE> of the push-components command, I should be able to push the component anyway, or at least I should be informed of this missing property in a clear, informative error message so that the developer can provide it where needed.

Maybe there could be a fix on the check being executed, such as the following

if(internal_tags_list && internal_tags_list.length > 0) 

but this I'll leave it to you

Steps to reproduce:

  1. create a components.json file to use as the components schema to push to Storyblok, with a component that is missing the mentioned property. For example:
{
  "components": [
    {
      "name": <COMPONENT_NAME>,
      "display_name": null,
      "created_at": <CREATION_AT>,
      "updated_at":  <UPDATED_AT>,
      "id": <ID>,
      "schema": {
        "contents": {
          "type": "bloks",
          "required": true,
          "display_name": <DISPLAY_NAME>,
          "key": <KEY>,
          "pos": 0
        }
      },
      "image": null,
      "preview_field": null,
      "is_root": false,
      "preview_tmpl": null,
      "is_nestable": true,
      "all_presets": [],
      "preset_id": null,
      "real_name": "container",
      "component_group_uuid": null,
      "color": "",
      "icon": "block-center-m",
      "internal_tags_list": []
    }
  ] 
}
  1. run the push-components command, for example storyblok push-components ./components.json --space <SPACE_ID>
@diaiunese-at-halueio diaiunese-at-halueio added the bug Something isn't working label Nov 5, 2024
@fulljames
Copy link

I seem to be getting a related error here where, if tags are populated on the source component and (presumably) the tag does not exist in the destination space the import for that component fails with a 422 Unprocessable entity

      "internal_tags_list": [
        {
          "id": <TAG_ID>,
          "name": "<TAG_NAME>"
        }
      ],
      "internal_tag_ids": [
        "<TAG_ID>"
      ],

results in

- Get presets from component <COMPONENT_NAME>
- Creating component <COMPONENT_NAME>...
X An error occurred when create component
Unprocessable Entity

If I set these arrays to be empty the import is successful.

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

No branches or pull requests

2 participants