-
Notifications
You must be signed in to change notification settings - Fork 397
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ssr-compiler): harmonize some wire errors (#5062)
Co-authored-by: Will Harney <[email protected]>
- Loading branch information
Showing
5 changed files
with
66 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -218,4 +218,4 @@ export const DecoratorErrors = { | |
level: DiagnosticLevel.Error, | ||
url: '', | ||
}, | ||
}; | ||
} as const; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright (c) 2024, Salesforce, Inc. | ||
* All rights reserved. | ||
* SPDX-License-Identifier: MIT | ||
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT | ||
*/ | ||
import { generateErrorMessage, type LWCErrorInfo } from '@lwc/errors'; | ||
|
||
// This type extracts the arguments in a string. Example: "Error {0} {1}" -> [string, string] | ||
type ExtractArguments< | ||
T extends string, | ||
Numbers extends number = never, | ||
Args extends string[] = [], | ||
> = T extends `${string}{${infer N extends number}}${infer R}` | ||
? N extends Numbers // Is `N` in the union of seen numbers? | ||
? ExtractArguments<R, Numbers, Args> // new `N`, add an argument | ||
: ExtractArguments<R, N | Numbers, [string, ...Args]> // `N` already accounted for | ||
: Args; // No `N` found, nothing more to check | ||
|
||
export function generateError<const T extends LWCErrorInfo>( | ||
error: T, | ||
...args: ExtractArguments<T['message']> | ||
): Error { | ||
return new Error(generateErrorMessage(error, args)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters