#Nest JS Commander fails w/ exit code 1 no logs

1 messages ยท Page 1 of 1 (latest)

steady ruin
#

Hey, getting a weird error just:

node@c907b8f450a6:/usr/src/app$ node dist/src/cli.js infer-types
Process exiting with code *: 1

I've removed a bunch of code and made it super simple and it usually falls down to injecting configService into constructor.

hoary ether
#

NEST_DEBUG=true
and try it again

#

I don't thing we can help much without the code, tho

steady ruin
#

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

opaque geyser
#

Most likely there's an error from Nest that isn't being logged. Set the logger explicitly.

CommandFactory.run(CliModule, { logger: new ConsoleLogger(), ...otherOptions });
steady ruin
#

yes got it

#

that makes sense

opaque geyser
#

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

steady ruin
#

yep!!

#

thats it

#

that atleast gives me errors

#

thank you!

#

how would I have figured that out w/o you!!

opaque geyser
steady ruin
#

hmm

#

must've missed it

#

@opaque geyser how does nesdt commander handle forwardRef(() => PlaceModule), ?

opaque geyser
#

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

steady ruin
#

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,
opaque geyser
#

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

steady ruin
#

okay @opaque geyser you know I appreciate you the mostest right?

#

anything I can do to debug this resolve dependency issue?

opaque geyser
#

Well, NEST_DEBUG will now help print out lines to see what's being resolved where

steady ruin
#

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.