Skip to content

Commit

Permalink
Improve error handling for module URLs in project settings
Browse files Browse the repository at this point in the history
  • Loading branch information
jldec committed May 1, 2024
1 parent 456f0e0 commit bc17d0c
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 bc17d0c

Please sign in to comment.