Repository: withastro/astro
File: packages/astro/src/core/errors/errors-data.ts (TypeScript)

Code before:
 * Make sure that all required fields are present, and that all fields are of the correct type.
 * You can check against the collection schema in your `src/content.config.*` file.
 * See the [Content collections documentation](https://docs.astro.build/en/guides/content-collections/) for more information.
 */
export const ContentEntryDataError = {
	name: 'ContentEntryDataError',
	title: 'Content entry data does not match schema.',
	message(collection: string, entryId: string, error: ZodError) {
		return [
			`**${String(collection)} → ${String(entryId)}** data does not match collection schema.\n`,
			...error.errors.map((zodError) => `  **${zodError.path.join('.')}**: ${zodError.message}`),
			'',
		].join('\n');
	},
	hint: 'See https://docs.astro.build/en/guides/content-collections/ for more information on content schemas.',
} satisfies ErrorData;

/**
 * @docs
 * @message
 * **Example error message:**<br/>
 * **blog** → **post** returned an invalid cache hint.<br/>
 * **maxAge**: Expected number, received string
 * @description
 * The loader for a live content collection returned an invalid cache hint.
 * Make sure that if you are using a cache hint, it is a valid object.
 * @see
 * - [Experimental live content](https://astro.build/en/reference/experimental-flags/live-content/)
 */
export const InvalidCacheHintError = {
	name: 'InvalidCacheHintError',
	title: 'Invalid cache hint.',
	message(collection: string, entryId: string | undefined, error: ZodError) {
		return [
			`**${String(collection)}${entryId ? ` → ${String(entryId)}` : ''}** returned an invalid cache hint.\n`,
			...error.errors.map((zodError) => `  **${zodError.path.join('.')}**: ${zodError.message}`),
			'',
		].join('\n');
	},
	hint: 'See https://docs.astro.build/en/reference/experimental-flags/live-content/ for more information.',
} satisfies ErrorData;

/**
 * @docs
 * @message
 * **Example error message:**<br/>
 * The schema cannot be a function for live collections. Please use a schema object instead. Check your collection definitions in your live content config file.
 * @description
 * Error in live content config.
 * @see
 * - [Experimental live content](https://astro.build/en/reference/experimental-flags/live-content/)

Review comment (bug):
```suggestion
 * Make sure that your cache hint object is properly formatted.
```
Just two quick things jump to mind:
- if an invalid cache hint was received, then presumably they *are* using a cache hint? So we can avoid that extra wording? (Or at least, safe enough? If someone reacts, "Wait, I didn't *think* I provided a cache hint..." then this message is also helpful to show them where to look for their error.)

- "It's invalid. Make it valid" could be a tiny bit more helpful if instead of "make it valid", we can prompt with what's likely to make it invalid, or at the very least, not duplicate "valid" which can feel like a "duh!" kind of error message. 😅  Both `tags` and `maxAge` appear to be optional, so it's probably not e.g. that one is missing, but something like that the type or syntax was wrong?

The other alternative is to be more descriptive about the *first* sentence, like:

> The loader for a live content collection could not determine a caching strategy (/how to cache your content). Make sure that your cache hint is a valid object.

I think either change to avoid duplication feels helpful!

Code after:
 * Make sure that all required fields are present, and that all fields are of the correct type.
 * You can check against the collection schema in your `src/content.config.*` file.
 * See the [Content collections documentation](https://docs.astro.build/en/guides/content-collections/) for more information.
 */
export const ContentEntryDataError = {
	name: 'ContentEntryDataError',
	title: 'Content entry data does not match schema.',
	message(collection: string, entryId: string, error: ZodError) {
		return [
			`**${String(collection)} → ${String(entryId)}** data does not match collection schema.\n`,
			...error.errors.map((zodError) => `  **${zodError.path.join('.')}**: ${zodError.message}`),
			'',
		].join('\n');
	},
	hint: 'See https://docs.astro.build/en/guides/content-collections/ for more information on content schemas.',
} satisfies ErrorData;

/**
 * @docs
 * @message
 * **Example error message:**<br/>
 * **blog** → **post** returned an invalid cache hint.<br/>
 * **maxAge**: Expected number, received string
 * @description
 * The loader for a live content collection returned an invalid cache hint.
 * Make sure that `cacheHint` is an object with the correct properties, or is undefined.
 * @see
 * - [Experimental live content](https://astro.build/en/reference/experimental-flags/live-content/)
 */
export const InvalidCacheHintError = {
	name: 'InvalidCacheHintError',
	title: 'Invalid cache hint.',
	message(collection: string, entryId: string | undefined, error: ZodError) {
		return [
			`**${String(collection)}${entryId ? ` → ${String(entryId)}` : ''}** returned an invalid cache hint.\n`,
			...error.errors.map((zodError) => `  **${zodError.path.join('.')}**: ${zodError.message}`),
			'',
		].join('\n');
	},
	hint: 'See https://docs.astro.build/en/reference/experimental-flags/live-content/ for more information.',
} satisfies ErrorData;

/**
 * @docs
 * @message
 * **Example error message:**<br/>
 * The schema cannot be a function for live collections. Please use a schema object instead. Check your collection definitions in your live content config file.
 * @description
 * Error in live content config.
 * @see
 * - [Experimental live content](https://astro.build/en/reference/experimental-flags/live-content/)