Skip to content

Commit

Permalink
fix: console.error prismaFmt errors
Browse files Browse the repository at this point in the history
Related #968
  • Loading branch information
Jolg42 committed Dec 23, 2021
1 parent 5e536a6 commit 8c87d37
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 12 deletions.
7 changes: 4 additions & 3 deletions packages/language-server/src/prisma-fmt/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ export default function format(
console.log('running format() from prisma-fmt')
try {
return prismaFmt.format(schema, JSON.stringify(options))
} catch (errors) {
} catch (e) {
if (onError) {
onError(
"prisma-fmt error'd during formatting. To get a more detailed output please see Prisma Language Server output. To see the output, go to View > Output from the toolbar, then select 'Prisma Language Server' in the Output panel.",
)
}
console.warn(

console.error(
"\nprisma-fmt error'd during formatting. Please report this issue on [Prisma Language Tools](https://github.com/prisma/language-tools/issues). \nLinter output:\n",
)
console.warn(errors)
console.error(e)

return schema
}
Expand Down
7 changes: 4 additions & 3 deletions packages/language-server/src/prisma-fmt/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ export default function lint(
try {
const result = prismaFmt.lint(text)
return JSON.parse(result) // eslint-disable-line @typescript-eslint/no-unsafe-return
} catch (errors) {
} catch (e) {
const errorMessage = "prisma-fmt error'd during linting.\n"

if (onError) {
onError(errorMessage + errors) // eslint-disable-line @typescript-eslint/restrict-plus-operands
onError(`${errorMessage} ${e as string}`)
}

console.error(errorMessage)
console.error(errors)
console.error(e)

return []
}
}
10 changes: 8 additions & 2 deletions packages/language-server/src/prisma-fmt/nativeTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,17 @@ export default function nativeTypeConstructors(
try {
const result = prismaFmt.native_types(text)
return JSON.parse(result) as NativeTypeConstructors[]
} catch (err) {
} catch (e) {
const errorMessage =
"prisma-fmt error'd during getting available native types.\n"

if (onError) {
onError(`prisma-fmt error'd during getting available native types. ${err}`)
onError(`${errorMessage} ${e as string}`)
}

console.error(errorMessage)
console.error(e)

return []
}
}
8 changes: 6 additions & 2 deletions packages/language-server/src/prisma-fmt/previewFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ export default function previewFeatures(
try {
const result = prismaFmt.preview_features()
return JSON.parse(result) as string[]
} catch (err) {
} catch (e) {
const errorMessage =
"prisma-fmt error'd during getting available preview features.\n"

if (onError) {
onError(errorMessage + err)
onError(`${errorMessage} ${e as string}`)
}

console.error(errorMessage)
console.error(e)

return []
}
}
10 changes: 8 additions & 2 deletions packages/language-server/src/prisma-fmt/referentialActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@ export default function referentialActions(
console.log('running referential_actions() from prisma-fmt')
const result = prismaFmt.referential_actions(text)
return JSON.parse(result) as string[]
} catch (err) {
} catch (e) {
const errorMessage =
"prisma-fmt error'd during getting available referential actions.\n"

if (onError) {
onError(`prisma-fmt error'd during getting available referential actions. ${err}`)
onError(`${errorMessage} ${e as string}`)
}

console.error(errorMessage)
console.error(e)

return []
}
}

0 comments on commit 8c87d37

Please sign in to comment.