Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@
"groupName": "typescript-tooling",
"matchPackageNames": ["@sanity/pkg-utils", "typescript"]
},
{
"description": "Always upgrade oxlint together",
"groupName": "oxlint",
"matchPackageNames": ["oxlint", "eslint-plugin-oxlint"]
},
{
"description": "Due to our usage of useEffectEvent we need to use the experimental version of the plugin. Otherwise the exhaustive-deps rule will have false negatives",
"matchPackageNames": [
Expand Down
3 changes: 2 additions & 1 deletion .oxlintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@
"eslint/no-unsafe-optional-chaining": "warn",
"promise/always-return": ["error", {"ignoreLastCallback": true}],
// Temporarily disabled, will be re-enabled in the near term
"unicorn/prefer-set-has": "off"
"unicorn/prefer-set-has": "off",
"no-array-reverse": "off" // Requires polyfills for older browsers
},
"overrides": [
{"files": ["scripts/**/*", "examples/functions/**/*"], "rules": {"no-console": "off"}}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
"lodash-es": "^4.17.21",
"minimist": "^1.2.8",
"npm-run-all2": "^6.2.6",
"oxlint": "1.14.0",
"oxlint": "1.16.0",
"pkg-pr-new": "^0.0.54",
"prettier": "catalog:",
"read-package-up": "^11.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/@repo/eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"eslint-config-turbo": "^2.5.6",
"eslint-import-resolver-typescript": "^4.4.4",
"eslint-plugin-import": "^2.32.0",
"eslint-plugin-oxlint": "1.14.0",
"eslint-plugin-oxlint": "1.16.0",
"eslint-plugin-react": "^7.37.5",
"eslint-plugin-react-hooks": "6.0.0-rc.2",
"eslint-plugin-react-hooks-with-use-effect-event": "npm:eslint-plugin-react-hooks@0.0.0-experimental-8a8e9a7e-20250912",
Expand Down
14 changes: 9 additions & 5 deletions packages/@sanity/cli/src/actions/init-project/initProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,12 @@ export default async function initSanity(
if (useDefaultPlan) {
print(`Using default plan.`)
} else {
throw new Error(`Coupon "${intendedCoupon}" does not exist`)
throw new Error(`Coupon "${intendedCoupon}" does not exist`, {cause: err})
}
} else {
throw new Error(`Unable to validate coupon, please try again later:\n\n${err.message}`)
throw new Error(`Unable to validate coupon, please try again later:\n\n${err.message}`, {
cause: err,
})
}
}
} else if (intendedPlan) {
Expand All @@ -228,10 +230,12 @@ export default async function initSanity(
if (useDefaultPlan) {
print(`Using default plan.`)
} else {
throw new Error(`Plan id "${intendedPlan}" does not exist`)
throw new Error(`Plan id "${intendedPlan}" does not exist`, {cause: err})
}
} else {
throw new Error(`Unable to validate plan, please try again later:\n\n${err.message}`)
throw new Error(`Unable to validate plan, please try again later:\n\n${err.message}`, {
cause: err,
})
}
}
}
Expand Down Expand Up @@ -855,7 +859,7 @@ export default async function initSanity(
userAction: 'select',
}
}
throw new Error(`Failed to communicate with the Sanity API:\n${err.message}`)
throw new Error(`Failed to communicate with the Sanity API:\n${err.message}`, {cause: err})
}

if (projects.length === 0 && unattended) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export function createSetTelemetryConsentAction(status: SettableConsentStatus):
const errorMessage = resultMessages[status].failure(err.response?.body?.message)
if (err.statusCode === 403) {
// throw without stack trace from original error
// oxlint-disable-next-line preserve-caught-error is intentional
throw new Error(errorMessage)
} else {
// if not 403, throw original error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default async function typegenGenerateAction(
// If the user has not provided a specific schema path (eg we're using the default), give some help
const hint =
codegenConfig.schema === './schema.json' ? ` - did you run "sanity schema extract"?` : ''
throw new Error(`Schema file not found: ${codegenConfig.schema}${hint}`)
throw new Error(`Schema file not found: ${codegenConfig.schema}${hint}`, {cause: err})
}
throw err
}
Expand Down
2 changes: 1 addition & 1 deletion packages/@sanity/cli/src/util/getCliVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export async function getCliPkg(): Promise<PackageJson> {
try {
data = await fs.readFile(path.join(cliPath, 'package.json'), 'utf-8')
} catch (err) {
throw new Error(`Unable to read @sanity/cli/package.json: ${err.message}`)
throw new Error(`Unable to read @sanity/cli/package.json: ${err.message}`, {cause: err})
}

return JSON.parse(data)
Expand Down
2 changes: 1 addition & 1 deletion packages/@sanity/cli/src/util/journeyConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export async function getAndWriteJourneySchema(data: JourneySchemaWorkerData): P
const indexContent = await assembleJourneyIndexContent(documentTypes)
await fs.writeFile(path.join(schemasPath, `index.${fileExtension}`), indexContent)
} catch (error) {
throw new Error(`Failed to fetch remote schema: ${error.message}`)
throw new Error(`Failed to fetch remote schema: ${error.message}`, {cause: error})
}
}

Expand Down
4 changes: 3 additions & 1 deletion packages/@sanity/cli/src/util/loadEnv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ export function loadEnv(
// custom error handling until https://github.com/motdotla/dotenv-expand/issues/65 is fixed upstream
// check for message "TypeError: Cannot read properties of undefined (reading 'split')"
if (e.message.includes('split')) {
throw new Error('dotenv-expand failed to expand env vars. Maybe you need to escape `$`?')
throw new Error('dotenv-expand failed to expand env vars. Maybe you need to escape `$`?', {
cause: e,
})
}
throw e
}
Expand Down
2 changes: 1 addition & 1 deletion packages/@sanity/cli/src/util/resolveRootDir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function resolveRootDir(cwd: string): string {
try {
return resolveProjectRoot(cwd) || cwd
} catch (err) {
throw new Error(`Error occurred trying to resolve project root:\n${err.message}`)
throw new Error(`Error occurred trying to resolve project root:\n${err.message}`, {cause: err})
}
}

Expand Down
5 changes: 4 additions & 1 deletion packages/@sanity/codegen/src/readConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ export async function readConfig(path: string): Promise<CodegenConfig> {
return configDefintion.parseAsync(json)
} catch (error) {
if (error instanceof z.ZodError) {
throw new Error(`Error in config file\n ${error.errors.map((err) => err.message).join('\n')}`)
throw new Error(
`Error in config file\n ${error.errors.map((err) => err.message).join('\n')}`,
{cause: error},
)
}
if (typeof error === 'object' && error !== null && 'code' in error && error.code === 'ENOENT') {
return configDefintion.parse({})
Expand Down
2 changes: 1 addition & 1 deletion packages/@sanity/util/src/createSafeJsonParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function createSafeJsonParser<Type>({errorLabel}: Options): Parser<Type>
const errorLine = JSON.parse(errorJson)
const error = errorLine && errorLine.error
if (error && error.description) {
throw new Error(`${errorLabel}: ${error.description}\n\n${errorJson}\n`)
throw new Error(`${errorLabel}: ${error.description}\n\n${errorJson}\n`, {cause: err})
}

throw err
Expand Down
1 change: 0 additions & 1 deletion packages/groq/package.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {defineConfig} from '@sanity/pkg-utils'

export default defineConfig({
...baseConfig,
legacyExports: false,
bundles: [
{source: './src/_exports.cts.ts', require: './lib/groq.cjs'},
{source: './src/_exports.mts.ts', import: './lib/groq.js'},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ async function chooseBackupIdPrompt(
return selected
}
} catch (err) {
throw new Error(`Failed to fetch backups for dataset ${datasetName}: ${err.message}`)
throw new Error(`Failed to fetch backups for dataset ${datasetName}: ${err.message}`, {
cause: err,
})
}

throw new Error('No backups found')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class PaginatedGetBackupStream extends Readable {
if (msg === undefined) {
msg = String(error)
}
throw new Error(`Downloading dataset backup failed: ${msg}`)
throw new Error(`Downloading dataset backup failed: ${msg}`, {cause: error})
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ async function getOrCreateStudioFromConfig({
spinner.fail()
// if the name is taken, it should return a 409 so we relay to the user
if ([402, 409].includes(e?.statusCode)) {
throw new Error(e?.response?.body?.message || 'Bad request') // just in case
throw new Error(e?.response?.body?.message || 'Bad request', {cause: e}) // just in case
}
debug('Error creating user application from config', e)
// otherwise, it's a fatal error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export async function deleteToken(
return true
} catch (err) {
if (err.statusCode === 404) {
throw new Error(`Token with ID "${tokenId}" not found`)
throw new Error(`Token with ID "${tokenId}" not found`, {cause: err})
}
throw err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ const downloadBackupCommand: CliCommandDefinition = {
} catch (error) {
progressSpinner.fail()
const {message} = parseApiErr(error)
throw new Error(`Downloading dataset backup failed: ${message}`)
throw new Error(`Downloading dataset backup failed: ${message}`, {cause: error})
}

docOutStream.end()
Expand All @@ -183,7 +183,7 @@ const downloadBackupCommand: CliCommandDefinition = {
})
} catch (err) {
progressSpinner.fail()
throw new Error(`Archiving backup failed: ${err.message}`)
throw new Error(`Archiving backup failed: ${err.message}`, {cause: err})
}

progressSpinner.set({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const listDatasetBackupCommand: CliCommandDefinition<ListDatasetBackupFlags> = {
query.before = flags.before
query.after = flags.after
} catch (err) {
throw new Error(`Parsing date flags: ${err}`)
throw new Error(`Parsing date flags: ${err}`, {cause: err})
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const deleteCorsOriginCommand: CliCommandDefinition = {
await client.request({method: 'DELETE', uri: `/cors/${originId}`})
output.print('Origin deleted')
} catch (err) {
throw new Error(`Origin deletion failed:\n${err.message}`)
throw new Error(`Origin deletion failed:\n${err.message}`, {cause: err})
}
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ export const createAliasHandler: CliCommandAction = async (args, context) => {
} successfully`,
)
} catch (err) {
throw new Error(`Dataset alias creation failed:\n${err.message}`)
throw new Error(`Dataset alias creation failed:\n${err.message}`, {cause: err})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@ export const linkAliasHandler: CliCommandAction = async (args, context) => {
await aliasClient.updateAlias(client, aliasName, datasetName)
output.print(`Dataset alias ${aliasOutputName} linked to ${datasetName} successfully`)
} catch (err) {
throw new Error(`Dataset alias link failed:\n${err.message}`)
throw new Error(`Dataset alias link failed:\n${err.message}`, {cause: err})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ export const unlinkAliasHandler: CliCommandAction<UnlinkFlags> = async (args, co
`Dataset alias ${aliasOutputName} unlinked from ${result.datasetName} successfully`,
)
} catch (err) {
throw new Error(`Dataset alias unlink failed:\n${err.message}`)
throw new Error(`Dataset alias unlink failed:\n${err.message}`, {cause: err})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const createDatasetCommand: CliCommandDefinition<CreateFlags> = {
await client.datasets.create(datasetName, {aclMode})
output.print('Dataset created successfully')
} catch (err) {
throw new Error(`Dataset creation failed:\n${err.message}`)
throw new Error(`Dataset creation failed:\n${err.message}`, {cause: err})
}
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ const deleteDocumentsCommand: CliCommandDefinition<DeleteFlags> = {
)
}
} catch (err) {
throw new Error(`Failed to delete ${pluralize('document', ids.length)}:\n${err.message}`)
throw new Error(`Failed to delete ${pluralize('document', ids.length)}:\n${err.message}`, {
cause: err,
})
}
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const getDocumentsCommand: CliCommandDefinition<GetDocumentFlags> = {

output.print(pretty ? colorizeJson(doc, chalk) : JSON.stringify(doc, null, 2))
} catch (err) {
throw new Error(`Failed to fetch document:\n${err.message}`)
throw new Error(`Failed to fetch document:\n${err.message}`, {cause: err})
}
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export default {

output.print(pretty ? colorizeJson(docs, chalk) : JSON.stringify(docs, null, 2))
} catch (err) {
throw new Error(`Failed to run query:\n${err.message}`)
throw new Error(`Failed to run query:\n${err.message}`, {cause: err})
}
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const deleteHookCommand: CliCommandDefinition = {
.config({apiVersion: '2021-10-04'})
.request({method: 'DELETE', uri: `/hooks/${hookId}`})
} catch (err) {
throw new Error(`Hook deletion failed:\n${err.message}`)
throw new Error(`Hook deletion failed:\n${err.message}`, {cause: err})
}
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const listHookLogsCommand: CliCommandDefinition<ListHookFlags> = {
messages = await client.request<HookMessage[]>({uri: `/hooks/${hookId}/messages`})
attempts = await client.request<DeliveryAttempt[]>({uri: `/hooks/${hookId}/attempts`})
} catch (err) {
throw new Error(`Hook logs retrieval failed:\n${err.message}`)
throw new Error(`Hook logs retrieval failed:\n${err.message}`, {cause: err})
}

const groupedAttempts = groupBy(attempts, 'messageId')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const listHooksCommand: CliCommandDefinition = {
.config({apiVersion: '2021-10-04'})
.request<Hook[]>({uri: '/hooks'})
} catch (err) {
throw new Error(`Hook list retrieval failed:\n${err.message}`)
throw new Error(`Hook list retrieval failed:\n${err.message}`, {cause: err})
}

hooks.forEach((hook) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const printHookAttemptCommand: CliCommandDefinition = {
try {
attempt = await client.request<DeliveryAttempt>({uri: `/hooks/attempts/${attemptId}`})
} catch (err) {
throw new Error(`Hook attempt retrieval failed:\n${err.message}`)
throw new Error(`Hook attempt retrieval failed:\n${err.message}`, {cause: err})
}

const {createdAt, resultCode, resultBody, failureReason, inProgress} = attempt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ const listMigrationCommand: CliCommandDefinition = {
)
return
}
throw new Error(`An error occurred while listing migrations: ${error.message}`)
throw new Error(`An error occurred while listing migrations: ${error.message}`, {
cause: error,
})
}
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function resolveMigrationScript(
mod = require(absolutePath)
} catch (err) {
if (err.code !== 'MODULE_NOT_FOUND') {
throw new Error(`Error: ${err.message}"`)
throw new Error(`Error: ${err.message}"`, {cause: err})
}
}
return {relativePath, absolutePath, mod}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const addTokenCommand: CliCommandDefinition<AddTokenFlags> = {
output.print('')
output.print('Copy the token above – this is your only chance to do so!')
} catch (err) {
throw new Error(`Token creation failed:\n${err.message}`)
throw new Error(`Token creation failed:\n${err.message}`, {cause: err})
}
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const deleteTokenCommand: CliCommandDefinition = {
output.print('Token deleted successfully')
}
} catch (err) {
throw new Error(`Token deletion failed:\n${err.message}`)
throw new Error(`Token deletion failed:\n${err.message}`, {cause: err})
}
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const listTokensCommand: CliCommandDefinition<ListTokensFlags> = {

table.printTable()
} catch (err) {
throw new Error(`Failed to list tokens:\n${err.message}`)
throw new Error(`Failed to list tokens:\n${err.message}`, {cause: err})
}
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export async function readPackageJson(filePath: string): Promise<PackageJson> {
try {
return JSON.parse(await readFile(filePath, 'utf8'))
} catch (err) {
throw new Error(`Failed to read "${filePath}": ${err.message}`)
throw new Error(`Failed to read "${filePath}": ${err.message}`, {cause: err})
}
}
/**
Expand All @@ -49,7 +49,7 @@ export async function readPackageManifest(
try {
manifest = {...defaults, ...(await readPackageJson(packageJsonPath))}
} catch (err) {
throw new Error(`Failed to read "${packageJsonPath}": ${err.message}`)
throw new Error(`Failed to read "${packageJsonPath}": ${err.message}`, {cause: err})
}

if (!isPackageManifest(manifest)) {
Expand Down
Loading
Loading