Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): Add abortOnError option in NestApplicationContextOptions #5327

Conversation

princechauhan1992
Copy link
Contributor

@princechauhan1992 princechauhan1992 commented Aug 25, 2020

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[x] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Other... Please describe:

What is the current behavior?

#5162

Issue Number: 5162

What is the new behavior?

An abortOnError flag is added in nestApplicationContext. By default the process is aborted, but if abortOnError is set to false,
error is rethrown instead of calling process.abort() or process.exit(1)

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

@princechauhan1992
Copy link
Contributor Author

@kamilmysliwiec This is my first contribution to an open source project, so I apologize in advance in case I have made any mistakes. Kindly suggest if any changes are required.

@coveralls
Copy link

coveralls commented Aug 25, 2020

Pull Request Test Coverage Report for Build 2b7063e7-43b1-4bfb-8314-d3471ed66c52

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 94.818%

Totals Coverage Status
Change from base Build 8421a20c-8cfe-4694-b0a7-b80f916cb093: 0.0%
Covered Lines: 4922
Relevant Lines: 5191

💛 - Coveralls

@kamilmysliwiec kamilmysliwiec merged commit c34d08d into nestjs:master Oct 29, 2020
@nikxco
Copy link

nikxco commented Jul 14, 2024

I'm using NestJS 10.0.0 and still having the same issue.
Following is my app module where i'm using yup to validate my environment variables which is working fine except the ValidationError doesn't have all the information.

app.module.ts

  imports: [
    ConfigModule.forRoot({
      isGlobal: true,
      cache: false
      expandVariables: true,
      envFilePath: ['./env/.env.local', './env/.env.database'],
      load: [databaseConfig, appConfig],
      validationSchema: EnvironmentVariableSchema,
      validationOptions: {
        abortEarly: false,
      },
    }),
    MongooseModule.forRootAsync({
      useFactory: async (configService: ConfigService) => ({
        dbName: configService.get<string>('database.name'),
        uri: configService.get<string>('database.uri'),
      }),
      inject: [ConfigService],
    }),
    UsersModule,
    DatabaseModule,
    VerificationsModule,
    SubscriptionsModule,
    JobsModule,
    ResumesModule,
    LocationsModule,
    LanguagesModule,
    AlertsModule,
    CampaignsModule,
    CategoriesModule,
    CompaniesModule,
    CoursesModule,
    CreditsModule,
    CurrenciesModule,
    DesignationsModule,
    InsightsModule,
    InstitutionsModule,
    NextAuthModule,
    NotificationsModule,
    OpenaiModule,
    ReportsModule,
    RewardsModule,
    TagsModule,
  ],
  controllers: [AppController],
  providers: [
    AppService,
    { provide: 'APP_NAME', useValue: 'NestJS' },
    { provide: 'APP_VERSION', useValue: '1.0.0' },
    { provide: 'APP_GUARD', useClass: ApiKeyGuard },
  ],
})
export class AppModule {}

main.ts file

async function bootstrap() {
  const logger = new Logger('Bootstrap');
  const app = await NestFactory.create(AppModule, { abortOnError: false });
  const configService = app.get(ConfigService);
  const PORT = configService.get('app.apiPort', 3000);
  app.setGlobalPrefix('v1');
  app.useGlobalInterceptors(new LoggingInterceptor());
  app.useGlobalFilters(new MongoExceptionFilter());
  await app.listen(PORT);
  logger.log(`Application is running on: http://localhost:${PORT}`);
}
bootstrap().catch((error) => {
    /******This catch block never gets executed.*******/
    console.error('Error in bootstrap++++++++++++++++++++++++', error);
  });

I want to log bootstrap errors to an external system and in order to do so I must be able to to catch those errors explicitly.

Am I missing something here?? Please help me with this. @kamilmysliwiec

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants