Skip to content

Commit

Permalink
fix: fixes no such file or directory when migration fails
Browse files Browse the repository at this point in the history
Fixes issue contentful#1332
  • Loading branch information
AssisrMatheus authored Jul 11, 2024
1 parent 65d60bd commit f5ee477
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/bin/lib/steps-errors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as fs from 'fs'
import * as url from 'url'
import * as cardinal from 'cardinal'
import * as _ from 'lodash'
import chalk from 'chalk'
Expand Down Expand Up @@ -33,11 +34,12 @@ const renderStepsErrors = function (errors: ValidationError[]) {
const messages = []

for (const file of Object.keys(errorsByFile)) {
const fileContents = fs.readFileSync(file, 'utf-8')
const filePath = file.startsWith(`file://`) ? url.fileURLToPath(file) : file;
const fileContents = fs.readFileSync(filePath, 'utf-8')
const highlightedCode = cardinal.highlight(fileContents, { linenos: true })
const lines = highlightedCode.split('\n')

const fileErrorsMessage = chalk`{red Errors in ${file}}\n\n`
const fileErrorsMessage = chalk`{red Errors in ${filePath}}\n\n`
const errorMessages = errorsByFile[file]
.map((error) => {
const intent = error.details.intent
Expand Down

0 comments on commit f5ee477

Please sign in to comment.