-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…-handle-project-errors Paraglide Gracefully handle project errors
- Loading branch information
Showing
7 changed files
with
84 additions
and
27 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@inlang/paraglide-unplugin": minor | ||
--- | ||
|
||
Only warn about non-fatal errors insetad of erroring |
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,5 @@ | ||
--- | ||
"@inlang/paraglide-js": minor | ||
--- | ||
|
||
Gracefully handle errors in the Inlang Project. Only crash on errors that are fatal to paraglide specifically |
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
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
38 changes: 38 additions & 0 deletions
38
inlang/source-code/paraglide/paraglide-js/src/services/error-handling.ts
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,38 @@ | ||
import type { InlangProject } from "@inlang/sdk" | ||
|
||
interface ModuleError extends Error { | ||
name: string | ||
module: string | ||
} | ||
|
||
export function classifyProjectErrors(errors: ReturnType<InlangProject["errors"]>) { | ||
const isModuleError = (error: Error): error is ModuleError => | ||
error instanceof Error && "name" in error && error.name.includes("Module") && "module" in error | ||
|
||
const [moduleErrors, otherErrors] = split(errors as Error[], isModuleError) | ||
|
||
const isFatalModuleError = (error: ModuleError): error is ModuleError => | ||
error.module.includes("plugin") | ||
const [fatalModuleErrors, nonFatalModuleErrors] = split(moduleErrors, isFatalModuleError) | ||
|
||
const fatalErrors = [...fatalModuleErrors, ...otherErrors] | ||
const nonFatalErrors = [...nonFatalModuleErrors] | ||
|
||
return { fatalErrors, nonFatalErrors } | ||
} | ||
|
||
/** | ||
* Splits an array into two arrays based on the predicate | ||
*/ | ||
function split<T, U extends T>(array: T[], predicate: (value: T) => value is U): [U[], T[]] { | ||
const result: U[] = [] | ||
const rest: T[] = [] | ||
for (const item of array) { | ||
if (predicate(item)) { | ||
result.push(item) | ||
} else { | ||
rest.push(item) | ||
} | ||
} | ||
return [result, rest] | ||
} |
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