Skip to content

Commit

Permalink
test(migrate): fix Windows path issues (#24126)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkomyno committed May 8, 2024
1 parent 52589ae commit 665eae1
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
4 changes: 1 addition & 3 deletions packages/internals/src/engine-commands/getConfig.ts
Expand Up @@ -4,7 +4,6 @@ import { getBinaryTargetForCurrentPlatform } from '@prisma/get-platform'
import * as E from 'fp-ts/Either'
import { pipe } from 'fp-ts/lib/function'
import { bold, red } from 'kleur/colors'
import path from 'path'
import { match } from 'ts-pattern'

import { ErrorArea, getWasmError, isWasmPanic, RustPanic, WasmPanic } from '../panic'
Expand Down Expand Up @@ -152,8 +151,7 @@ export async function getConfig(options: GetConfigOptions): Promise<ConfigMetaFo
return panic
}

let errorOutput = e.error.message
errorOutput = errorOutput.replaceAll(process.cwd() + path.sep, '')
const errorOutput = e.error.message
return new GetConfigError(parseQueryEngineError({ errorOutput, reason: e.reason }))
})
.otherwise((e) => {
Expand Down
4 changes: 3 additions & 1 deletion packages/internals/src/engine-commands/queryEngineCommons.ts
Expand Up @@ -5,6 +5,8 @@ import fs from 'fs'
import { bold, red } from 'kleur/colors'
import { match, P } from 'ts-pattern'

import { relativizePathInPSLError } from './relativizePathInPSLError'

export function unlinkTempDatamodelPath(options: { datamodelPath?: string }, tempDatamodelPath: string | undefined) {
return TE.tryCatch(
() => {
Expand Down Expand Up @@ -67,7 +69,7 @@ export function parseQueryEngineError({ errorOutput, reason }: ParseQueryEngineE
() => ({ _tag: 'unparsed' as const, message: errorOutput, reason }),
),
E.map((errorOutputAsJSON: Record<string, string>) => {
const defaultMessage = red(bold(errorOutputAsJSON.message))
const defaultMessage = red(bold(relativizePathInPSLError(errorOutputAsJSON.message)))
const getConfigErrorInit = match(errorOutputAsJSON)
.with({ error_code: 'P1012' }, (eJSON) => {
return {
Expand Down
@@ -0,0 +1,8 @@
import path from 'node:path'

// This function ensures that PSL errors pointing to an absolute schema path
// display a relative path (w.r.t. the current working directory) instead.
// This can potentially be replaced by https://github.com/prisma/team-orm/issues/1127.
export function relativizePathInPSLError(error: string): string {
return error.replaceAll(process.cwd() + path.sep, '')
}
5 changes: 2 additions & 3 deletions packages/internals/src/engine-commands/validate.ts
Expand Up @@ -2,14 +2,14 @@ import Debug from '@prisma/debug'
import * as E from 'fp-ts/Either'
import { pipe } from 'fp-ts/lib/function'
import { bold, red } from 'kleur/colors'
import path from 'path'
import { match } from 'ts-pattern'

import { ErrorArea, getWasmError, isWasmPanic, RustPanic, WasmPanic } from '../panic'
import { debugMultipleSchemaPaths, debugMultipleSchemas, type MultipleSchemas } from '../utils/schemaFileInput'
import { prismaSchemaWasm } from '../wasm'
import { addVersionDetailsToErrorMessage } from './errorHelpers'
import { createDebugErrorType, parseQueryEngineError, QueryEngineErrorInit } from './queryEngineCommons'
import { relativizePathInPSLError } from './relativizePathInPSLError'

const debug = Debug('prisma:validate')

Expand All @@ -21,11 +21,10 @@ export class ValidateError extends Error {
constructor(params: QueryEngineErrorInit) {
const constructedErrorMessage = match(params)
.with({ _tag: 'parsed' }, ({ errorCode, message, reason }) => {
message = message.replaceAll(process.cwd() + path.sep, '')
const errorCodeMessage = errorCode ? `Error code: ${errorCode}` : ''
return `${reason}
${errorCodeMessage}
${message}`
${relativizePathInPSLError(message)}`
})
.with({ _tag: 'unparsed' }, ({ message, reason }) => {
const detailsHeader = red(bold('Details:'))
Expand Down

0 comments on commit 665eae1

Please sign in to comment.