loopbackio / loopbackio/loopback-next

lb4 repository tool error if datasource is using injection

Open
#8,015 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug CLI
Dominant language
TypeScript
Stars
5.1k
Forks
1.1k
Avg merge
2d 21h
Merged PRs (30d)
27

Description

I have a simple data source, whos config is loaded via injection:

export class MainDataSource extends juggler.DataSource
  implements LifeCycleObserver {
  static dataSourceName = 'Main';

  constructor(
    @config()
    dsConfig: object,
  ) {
    super(dsConfig);
  }
}

Application.ts:
this.configure('datasources.Main').to(options.datasources?.Main || {});

When running the repository scaffolding tool the following error occurs:
(node:24064) UnhandledPromiseRejectionWarning: Error: Cannot load C:\lb4\src\datasources\main.datasource.config.json: ENOENT: no such file or directory, open 'C:\lb4\src\datasources\main.datasource.config.json'

I am temporarily suppressing the error by adding a main.datasource.config.json file in the source directory.

However, this scaffolding tool should not require a fully configured data source to generate simple repositories. If the configuration cannot be found, it should just emit a warning, but still allow the tool to run and generate a non-customized class using the basic boilerplate.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the injected datasource setup in Application.ts and reproduce the repository scaffolding command using the missing src/datasources/main.datasource.config.json path. Trace how the tool handles the missing configuration, then verify that it warns and still generates the basic repository class without requiring the file.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, typescript
Domain
cli, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.