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

Error message is not clear that the dataset is missing when applying a migration #7528

Open
omar-ebrahim opened this issue Sep 19, 2024 · 1 comment

Comments

@omar-ebrahim
Copy link

If you find a security vulnerability, do NOT open an issue. Email [email protected] instead.

Describe the bug

When running a migration using npx sanity migration run MIGRATIONNAME and the dataset is missing, it defaults to ~dummy-placeholder-dataset-. When it runs and the dataset its missing, and defaults to the placeholder, it runs and produces a HTTP error

Project id:  c53pjo6p
Dataset:     ~dummy-placeholder-dataset-
HTTPError: Dataset alias not found: Dataset alias "dummy-placeholder-dataset-" not found for project ID "c53pjo6p"
    at assert2xx (/Users/omar/DEV/SanityStudioMigration/sanitymigrationtest/node_modules/@sanity/migrate/lib/index.js:747:278)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async fetchStream (/Users/omar/DEV/SanityStudioMigration/sanitymigrationtest/node_modules/@sanity/migrate/lib/index.js:752:7)
    at async Object.dryRun (/Users/omar/DEV/SanityStudioMigration/sanitymigrationtest/node_modules/@sanity/migrate/lib/index.js:912:5)
    at async dryRunHandler (/Users/omar/DEV/SanityStudioMigration/sanitymigrationtest/node_modules/sanity/lib/_chunks-cjs/_internal.js:2871:24) {
  statusCode: 404
}
Unhandled rejection: HTTPError: Dataset alias not found: Dataset alias "dummy-placeholder-dataset-" not found for project ID "c53pjo6p"
    at assert2xx (/Users/omar/DEV/SanityStudioMigration/sanitymigrationtest/node_modules/@sanity/migrate/lib/index.js:747:278)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async fetchStream (/Users/omar/DEV/SanityStudioMigration/sanitymigrationtest/node_modules/@sanity/migrate/lib/index.js:752:7)
    at async Object.dryRun (/Users/omar/DEV/SanityStudioMigration/sanitymigrationtest/node_modules/@sanity/migrate/lib/index.js:912:5)
    at async dryRunHandler (/Users/omar/DEV/SanityStudioMigration/sanitymigrationtest/node_modules/sanity/lib/_chunks-cjs/_internal.js:2871:24)

As the dataset is required and we're not going to see a dataset with the name ~dummy-placeholder-dataset-, it should probably error instead before creating the client

To Reproduce

Steps to reproduce the behavior:

I've created a repo demonstrating it here https://github.com/omar-ebrahim/SanityStudioMigration

npm create sanity@latest -- --project PROJECTID --dataset DATASET --template clean

To run the migration

cd sanitymigrationtest

and then ensure that the dataset is commented out in sanity.cli.ts

export default defineCliConfig({
  api: {
    projectId: 'c53pjo6p',
    /**
     * comment out this line to see the error
     */
    // dataset: 'production'
  },
  /**
   * Enable auto-updates for studios.
   * Learn more at https://www.sanity.io/docs/cli#auto-updates
   */
  autoUpdates: true,
})

npx sanity migration run updatename

Expected behavior

An error explaining what is missing. Something like the below

if (!apiConfig.dataset) {
    throw new Error("'dataset' has not been provided to the apiConfig")
}

Screenshots
If applicable, add screenshots to help explain your problem.

Which versions of Sanity are you using?

Run sanity versions in the terminal and copy-paste the result here.

omar@Omars-MacBook-Pro sanitymigrationtest % sanity versions                                    
@sanity/cli (global)          3.57.4 (up to date)
@sanity/eslint-config-studio   4.0.0 (up to date)
@sanity/vision                3.57.4 (up to date)
sanity                        3.57.4 (up to date)

What operating system are you using?

macOS Sonoma 14.7
Windows 11

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

Run npm -v && node -v in the terminal and copy-paste the result here.

omar@Omars-MacBook-Pro sanitymigrationtest % npm -v && node -v
10.6.0
v22.0.0

Additional context

Add any other context about the problem here.

Security issue?

Any security issues should be submitted directly to [email protected]. In order to determine whether you are dealing with a security issue, ask yourself these two questions:

  • Can I access something that's not mine, or something I shouldn't have access to?
  • Can I disable something for other people? If the answer to either of those two questions are "yes", then you're probably dealing with a security issue. Note that even if you answer "no" to both questions, you may still be dealing with a security issue, so if you're unsure, just email us at [[email protected]](mailto:[email protected].
@omar-ebrahim
Copy link
Author

Note, nothing is actually broken here, it's just the actual error in unclear. I feel that having a guard statement will prevent a HTTP call being created with an invalid dataset

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant