Skip to content

Commit

Permalink
chore: prettier composite errors (#587)
Browse files Browse the repository at this point in the history
  • Loading branch information
leanmendoza authored May 15, 2023
1 parent adaaaa2 commit 561a19a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
5 changes: 5 additions & 0 deletions packages/@dcl/sdk-commands/src/logic/beautiful-logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,8 @@ export function printSuccess(logger: ILoggerComponent.ILogger, operationSuccessf
logger.log(summary)
}
}

export function printError(logger: ILoggerComponent.ILogger, comment: string, error: Error) {
logger.log(colors.redBright(comment))
logger.error(error)
}
7 changes: 4 additions & 3 deletions packages/@dcl/sdk-commands/src/logic/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import path from 'path'
import { pathToFileURL } from 'url'
import { CliComponents } from '../components'
import { colors } from '../components/log'
import { printProgressInfo, printProgressStep } from './beautiful-logs'
import { printProgressInfo, printProgressStep, printWarning } from './beautiful-logs'
import { CliError } from './error'
import { getAllComposites } from './composite'

Expand Down Expand Up @@ -206,8 +206,9 @@ function compositeLoader(components: BundleComponents, options: CompileOptions):
watchFiles = data.watchFiles

if (data.withErrors) {
components.logger.log(
'Warning: some composites are not included because of errors while compiling them. There can be unexpected behavior in the scene, check the errors and try to fix them.'
printWarning(
components.logger,
'Some composites are not included because of errors while compiling them. There can be unexpected behavior in the scene, check the errors and try to fix them.'
)
}
}
Expand Down
9 changes: 6 additions & 3 deletions packages/@dcl/sdk-commands/src/logic/composite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { globSync } from 'glob'
import path from 'path'
import { CliComponents } from '../components'
import { Composite, Engine } from '@dcl/ecs/dist-cjs'
import { printError } from './beautiful-logs'

type CompositeComponents = Pick<CliComponents, 'logger' | 'fs'>

Expand All @@ -20,8 +21,10 @@ export async function getAllComposites(
const json = JSON.parse(textDecoder.decode(fileBuffer))
composites[file] = Composite.fromJson(json)
} catch (err: any) {
components.logger.log(
`Composite '${file}' can't be read. Please check if is a valid JSON and composite formated. ${err.stack}`
printError(
components.logger,
`Composite '${file}' can't be read. Please check if is a valid JSON and composite formated.`,
err
)
withErrors = true
}
Expand All @@ -45,7 +48,7 @@ export async function getAllComposites(
Composite.instance(engine, composite, compositeProvider)
compositeLines.push(`'${composite.src}':${JSON.stringify(Composite.toJson(composite.composite))}`)
} catch (err: any) {
components.logger.log(`Composite '${compositeSource}' can't be instanced ${err.stack}`)
printError(components.logger, `Composite '${compositeSource}' can't be instanced.`, err)
withErrors = true
}
}
Expand Down

0 comments on commit 561a19a

Please sign in to comment.