Skip to content

chore: provide links to documentation for errors/warnings #14629

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

Merged
merged 7 commits into from
Dec 9, 2024
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 .changeset/breezy-feet-knock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

chore: provide links to documentation for errors/warnings
12 changes: 7 additions & 5 deletions packages/svelte/scripts/process-messages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ function transform(name, dest) {
};

for (let i = 0; i < node.expressions.length; i += 1) {
const q = node.quasis[i + 1];
const q = structuredClone(node.quasis[i + 1]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's this change about?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(reverting it doesn't cause any tests to fail)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert it and rebuild the generated messages then you'll see it - later code does mutate properties and that can pollute the node across codes

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, i see

const e = node.expressions[i];

if (e.type === 'Literal' && e.value === 'CODE') {
Expand All @@ -355,10 +355,12 @@ function transform(name, dest) {
}

if (message.type === 'TemplateLiteral') {
quasi.value.raw += message.quasis[0].value.raw + q.value.raw;
out.quasis.push(...message.quasis.slice(1));
out.expressions.push(...message.expressions);
quasi = message.quasis[message.quasis.length - 1];
const m = structuredClone(message);
quasi.value.raw += m.quasis[0].value.raw;
out.quasis.push(...m.quasis.slice(1));
out.expressions.push(...m.expressions);
quasi = m.quasis[m.quasis.length - 1];
quasi.value.raw += q.value.raw;
continue;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import { DEV } from 'esm-env';
*/
export function CODE(PARAMETER) {
if (DEV) {
const error = new Error(`${'CODE'}\n${MESSAGE}`);
const error = new Error(`${'CODE'}\n${MESSAGE}\nhttps://svelte.dev/e/${'CODE'}`);
error.name = 'Svelte error';
throw error;
} else {
// TODO print a link to the documentation
throw new Error('CODE');
throw new Error(`https://svelte.dev/e/${'CODE'}`);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ var normal = 'font-weight: normal';
*/
export function CODE(PARAMETER) {
if (DEV) {
console.warn(`%c[svelte] ${'CODE'}\n%c${MESSAGE}`, bold, normal);
console.warn(
`%c[svelte] ${'CODE'}\n%c${MESSAGE}\nhttps://svelte.dev/e/${'CODE'}`,
bold,
normal
);
} else {
// TODO print a link to the documentation
console.warn('CODE');
console.warn(`https://svelte.dev/e/${'CODE'}`);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ function e(node, code, message) {
* @returns {never}
*/
export function CODE(node, PARAMETER) {
e(node, 'CODE', MESSAGE);
e(node, 'CODE', `${MESSAGE}\nhttps://svelte.dev/e/${'CODE'}`);
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ export const codes = CODES;
* @param {string} PARAMETER
*/
export function CODE(node, PARAMETER) {
w(node, 'CODE', MESSAGE);
w(node, 'CODE', `${MESSAGE}\nhttps://svelte.dev/e/${'CODE'}`);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @returns {never}
*/
export function CODE(PARAMETER) {
const error = new Error(`${'CODE'}\n${MESSAGE}`);
const error = new Error(`${'CODE'}\n${MESSAGE}\nhttps://svelte.dev/e/${'CODE'}`);
error.name = 'Svelte error';
throw error;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import { DEV } from 'esm-env';
*/
export function CODE(PARAMETER) {
if (DEV) {
const error = new Error(`${'CODE'}\n${MESSAGE}`);
const error = new Error(`${'CODE'}\n${MESSAGE}\nhttps://svelte.dev/e/${'CODE'}`);
error.name = 'Svelte error';
throw error;
} else {
// TODO print a link to the documentation
throw new Error('CODE');
throw new Error(`https://svelte.dev/e/${'CODE'}`);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ var normal = 'font-weight: normal';
*/
export function CODE(PARAMETER) {
if (DEV) {
console.warn(`%c[svelte] ${'CODE'}\n%c${MESSAGE}`, bold, normal);
console.warn(
`%c[svelte] ${'CODE'}\n%c${MESSAGE}\nhttps://svelte.dev/e/${'CODE'}`,
bold,
normal
);
} else {
// TODO print a link to the documentation
console.warn('CODE');
console.warn(`https://svelte.dev/e/${'CODE'}`);
}
}
Loading
Loading