question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CLI: sanity dataset import fails on missing metadata

See original GitHub issue

Describe the bug

I’m running sanity dataset export production && sanity dataset import production.tar.gz staging --replace to sync my production dataset to my staging dataset.

One of my images is missing some metadata. During the import, this image throws an error and the whole process is stopped:

✔ Exporting documents... (66/66)
✔ Downloading assets... (643/643)
✔ Adding assets to archive...
✔ Clearing temporary files...
Export finished (5m 28.8s)
✔ [100%] Fetching available datasets
✔ [100%] Reading/validating data file (223ms)
✔ [100%] Importing documents (2.47s)
✖ [ 71%] Importing assets (files/images) (46.81s)
o: Failed to upload image @ file:///var/folders/d7/tlsyl3dx2f73v9j7ght57cqm0000gn/T/sanity-import/production-export-2019-04-19t20-36-52-029z/images/542138d111351763702ad45995e5737409c13278-2192x2852.png:
Bad Request - Invalid image, could not read metadata
    at onResponse (~/Sites/myproject/myproject.com/node_modules/@sanity/cli/bin/sanity-cli.js:6489:535)
    at t.(anonymous function).reduce (~/Sites/myproject/myproject.com/node_modules/@sanity/cli/bin/sanity-cli.js:4895:242)
    at Array.reduce (<anonymous>)
    at ~/Sites/myproject/myproject.com/node_modules/@sanity/cli/bin/sanity-cli.js:4895:226
    at ~/Sites/myproject/myproject.com/node_modules/@sanity/cli/bin/sanity-cli.js:4883:919
    at a (~/Sites/myproject/myproject.com/node_modules/@sanity/cli/bin/sanity-cli.js:4883:1028)
    at E (~/Sites/myproject/myproject.com/node_modules/@sanity/cli/bin/sanity-cli.js:4931:1352)
    at u (~/Sites/myproject/myproject.com/node_modules/@sanity/cli/bin/sanity-cli.js:4931:2878)
    at s.<anonymous> (~/Sites/myproject/myproject.com/node_modules/@sanity/cli/bin/sanity-cli.js:2345:181)
error Command failed with exit code 1.

To Reproduce

You’re welcome to give this a try with the same dataset (I just ask that you import it into a separate instance). You can DM me on slack for the project info.

Expected behavior

I would expect (or hope) that this command would bypass the broken image, and report it as a warning at the end of the command. Or, better yet, find some way to repair the missing metadata.

Which versions of Sanity are you using?

@sanity/cli             0.140.14 (up to date)
@sanity/base            0.140.12 (up to date)
@sanity/cli             0.140.14 (up to date)
@sanity/components      0.140.12 (up to date)
@sanity/core            0.140.12 (up to date)
@sanity/default-layout  0.140.14 (up to date)
@sanity/default-login   0.140.15 (up to date)
@sanity/desk-tool       0.140.14 (up to date)
@sanity/image-url       0.140.12 (up to date)
@sanity/vision          0.140.14 (up to date)

What operating system are you using?

Mac OS

Which versions of Node.js / npm are you running?

6.9.0
v10.5.0

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
ryaninventscommented, Feb 25, 2021

I think this has recurred; I’m on @sanity/cli 2.4.0

-> % sanity -v
@sanity/cli version 2.4.0

-> % sanity dataset import ~/Documents/production-export-2021-02-24t20-10-18-618z staging --replace

✔ [100%] Fetching available datasets
✔ [100%] Reading/validating data file (522ms)
✔ [100%] Importing documents (1.72s)
✖ [  6%] Importing assets (files/images) (8.08s)

o: Failed to upload image @ file:///Users/ryan/Documents/production-export-2021-02-24t20-10-18-618z/images/151c6747b6e255b514965955ad444ac71c570f63-3000x2000.png:
Bad Request - Invalid image, could not read metadata
    at onResponse (~/.local/share/npm/lib/node_modules/@sanity/cli/bin/sanity-cli.js:4180:533)
    at ~/.local/share/npm/lib/node_modules/@sanity/cli/bin/sanity-cli.js:2736:279
    at ~/.local/share/npm/lib/node_modules/@sanity/cli/bin/sanity-cli.js:2724:918
    at ~/.local/share/npm/lib/node_modules/@sanity/cli/bin/sanity-cli.js:2724:1026
    at E (~/.local/share/npm/lib/node_modules/@sanity/cli/bin/sanity-cli.js:2772:1332)
    at ~/.local/share/npm/lib/node_modules/@sanity/cli/bin/sanity-cli.js:2772:2845
    at s.<anonymous> (~/.local/share/npm/lib/node_modules/@sanity/cli/bin/sanity-cli.js:1332:100)
    at A (~/.local/share/npm/lib/node_modules/@sanity/cli/bin/sanity-cli.js:1350:6029)
1reaction
good-ideacommented, May 13, 2019

This is still breaking for me. When I unpack the archive and find the files that cause the issue, they are “broken” ones like this:

image

$ sanity dataset import kame.tar.gz staging --replace
✔ [100%] Fetching available datasets
✔ [100%] Reading/validating data file (229ms)
✔ [100%] Importing documents (1.57s)
✖ [ 64%] Importing assets (files/images) (21.75s)
o: Failed to upload image @ file:///private/var/folders/d7/tlsyl3dx2f73v9j7ght57cqm0000gn/T/4b5727551e555a1cf5ff9af1fe839648/sanity-import/kame-export-2019-05-13t23-38-51-685z/images/2e979401b96dc1b433547cc7d0fac41828ecf44f-2520x2520.png:
Bad Request - Invalid image, could not read metadata
    at onResponse (~/Sites/hikawa.studio/hikawa.studio/node_modules/@sanity/cli/bin/sanity-cli.js:6483:539)
    at t.(anonymous function).reduce (~/Sites/hikawa.studio/hikawa.studio/node_modules/@sanity/cli/bin/sanity-cli.js:6501:242)
 

The image isn’t broken in the main dataset - when I explore the files straight from the Sanity dashboard - but appears to have been messed up somehow in the download process.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Importing Data - Sanity.io
The import will fail if an incoming document already exists in the dataset. A couple of options allow you to amend this: --replace...
Read more >
Migrating Data - Sanity.io
Sanity provides two workflows for doing this: Migrating using the API or using the CLI to export and import datasets. Migrate using the...
Read more >
Mutations - Sanity.io
curl 'https://<project-id>.api.sanity.io/v2021-06-07/data/mutate/<dataset-name> ... The operation will fail if a document by the provided ID already exists.
Read more >
Datasets - Sanity.io
Datasets can be created and managed using the sanity command-line tool, ... You can export and import content to datasets, as well as...
Read more >
Setting up with Sanity CLI
No problem, we have instructions. npm install -g @sanity/cli. The command line tool is used to set up new projects, manage datasets, import...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found