Skip to content

Commit

Permalink
Merge pull request #2687 from opral/clearer-project-settings-errors
Browse files Browse the repository at this point in the history
MESDK-82 Improve error handling for module URLs in project settings
  • Loading branch information
jldec authored May 1, 2024
2 parents 456f0e0 + bc17d0c commit 09047a9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .changeset/witty-icons-kick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@inlang/project-settings": patch
"@inlang/sdk": patch
---

Improve error handling for module URLs in project settings
20 changes: 16 additions & 4 deletions inlang/source-code/sdk/src/errors.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { SchemaOptions } from "@sinclair/typebox"
import type { ValueError } from "@sinclair/typebox/errors"

export class LoadProjectInvalidArgument extends Error {
Expand All @@ -11,15 +12,26 @@ export class ProjectSettingsInvalidError extends Error {
constructor(options: { errors: ValueError[] }) {
// TODO: beatufiy ValueErrors
super(
`The project settings are invalid:\n\n${options.errors
.filter((error) => error.path)
.map((error) => `"${error.path}":\n\n${error.message}`)
.join("\n")}`
`The project settings are invalid:
${options.errors
.filter((error) => error.path)
.map(FormatProjectSettingsError)
.join("\n")}`
)
this.name = "ProjectSettingsInvalidError"
}
}

function FormatProjectSettingsError(error: ValueError) {
let msg = `${error.message} at ${error.path}`
if (error.path.startsWith("/modules/")) {
msg += `
value = "${error.value}"
- ${error.schema.allOf.map((o: SchemaOptions) => `${o.description ?? ""}`).join("\n- ")}`
}
return msg
}

export class ProjectSettingsFileJSONSyntaxError extends Error {
constructor(options: { cause: ErrorOptions["cause"]; path: string }) {
super(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ const InternalProjectSettings = Type.Object({
}),
Type.String({
pattern: "^(?!.*@\\d\\.)[^]*$",
description:
"The module can only contain a major version number (ComVer, not SemVer). See https://inlang.com/documentation/comver",
description: "The module can only contain a major version number.",
}),
]),
{
Expand Down

0 comments on commit 09047a9

Please sign in to comment.