#Nest JS Commander fails w/ exit code 1 no logs
1 messages ยท Page 1 of 1 (latest)
NEST_DEBUG=true
and try it again
I don't thing we can help much without the code, tho
cli.ts:
import { CliModule } from './cli.module'
process.on('unhandledRejection', function (err) {
console.log('Unhandled Rejection', err)
})
process.on('exit', (code) => {
console.log(`Process exiting with code *: ${code}`)
})
process.on('SIGTERM', () => {
console.log('Received SIGTERM signal')
})
async function bootstrap() {
await CommandFactory.run(CliModule, {
serviceErrorHandler: (err) => {
console.error(err)
process.exit(1) // this could also be a 0 depending on how you want to handle the exit code
},
errorHandler: (err) => {
console.error(err)
process.exit(1) // this could also be a 0 depending on how you want to handle the exit code
},
})
}
bootstrap().catch(console.dir)
infer-type command:
@Command({
name: 'infer-type',
description:
'Classify entity types from CSV data using heuristics and account matching',
})
export class InferTypeCommand extends CommandRunner {
constructor(private readonly config: ConfigService) {
super()
}
async run(passedParams: string[], options: InferTypeOptions): Promise<void> {
const {
csvFile,
outputFile,
configPreset = 'default',
displayNameField = 'display_name',
urlField = 'url',
stateField = 'state_abbr',
onlyClassify = false,
} = options
console.log(`๐ Processing CSV file: ${csvFile}`)
console.log(`๐ Using config preset: ${configPreset}`)
console.log(`๐ท๏ธ Display name field: ${displayNameField}`)
console.log(`๐ URL field: ${urlField}`)
console.log(`๐ State field: ${stateField}`)
console.log(`๐ฏ Only classify (no account matching): ${onlyClassify}`)
}
}
it just swallows errors
shows no errors
Most likely there's an error from Nest that isn't being logged. Set the logger explicitly.
CommandFactory.run(CliModule, { logger: new ConsoleLogger(), ...otherOptions });
It's made to swallow the startup logs by default so that (when published) the end user doesn't need to see all of the Nest logs
yep!!
thats it
that atleast gives me errors
thank you!
how would I have figured that out w/o you!!
hmm
must've missed it
@opaque geyser how does nesdt commander handle forwardRef(() => PlaceModule), ?
Shouldn't be any different than how Nest does it, because it's all Nest under the hood. The abstraction is just for running the cli and making the commands. Otherwise it's still a Nest application.
It uses createApplicationContext under the hood, just like you can with NestFactory
hmm okay
Potential solutions:
- Is AccountMatchCLIModule a valid NestJS module?
- If PlaceService is a provider, is it part of the current AccountMatchCLIModule?
- If PlaceService is exported from a separate @Module, is that module imported within AccountMatchCLIModule?
@Module({
imports: [ /* the Module containing PlaceService */ ]
})
Error: Nest can't resolve dependencies of the AccountMatchService (AccountMatchRecordModel, ?, AWSService, TemporalQueue_default, CSVJobsService). Please make sure that the argument PlaceService at index [1] is available in the AccountMatchCLIModule context.
getting this which is the forwardRef.
I am also importing our AppModule so it should have all modules it needs.
@Inject(forwardRef(() => PlaceService))
private readonly placeService: PlaceService,
I can't imagine a reason that a forwardRef wouldn't work, because it's all regular nest being executed. And without a reproduction, I can't really debug
okay @opaque geyser you know I appreciate you the mostest right?
anything I can do to debug this resolve dependency issue?
Well, NEST_DEBUG will now help print out lines to see what's being resolved where
NEST_DEBUG
idk if thats helpful
not for me, personally
ok I got it working but not sure why
if I have this module:
import { AccountMatchModule } from './account.match.module'
import { InferTypeCommand } from './commands/infer.type.command'
import { Module } from '@nestjs/common'
@Module({
imports: [AccountMatchModule],
providers: [AccountMatchService, InferTypeCommand],
})
export class AccountMatchCLIModule {}
and import this in my cli.module -- it fails. but if I import the AccountMatchModule it's self it works
thanks for help again, talk soon.