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

[Bug]: Can't use the configs defined in a submodule. #40356

Closed
sumedhe opened this issue May 7, 2023 · 1 comment
Closed

[Bug]: Can't use the configs defined in a submodule. #40356

sumedhe opened this issue May 7, 2023 · 1 comment
Labels
Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Team/jBallerina All the issues related to BIR, JVM backend code generation and runtime Type/Question userCategory/Compilation

Comments

@sumedhe
Copy link

sumedhe commented May 7, 2023

Description

When using configurations in the ballerina config model, we are defining types that correspond to the configs in the toml file. I have encountered the following issue with configuration usage.

Steps to Reproduce

  1. Create a new ballerina app and create two modules named mymodule.
  2. Create the Config.toml file in the root of the project.
    [myconfig]
    port = 8005
  3. In the myconfig file, define a config type as below.
    public type ServerConfig record {
        int port;
    };
    
    public configurable ServerConfig myconfig = {
        port: 8081
    };
  4. in the main.bal file use the config initialized in the mymodule as below.
    public function main() {
        io:print(mymodule:myconfig.port);
    }
  5. Start with bal run and it will show the following error.
    Running executable
    
    error: [Config.toml:(11:1,12:12)] unused configuration value 'myconfig'
    error: [Config.toml:(12:1,12:12)] unused configuration value 'myconfig.port'

Affected Version(s)

Ballerina 2201.5.0 (Swan Lake Update 5)
Language specification 2022R4
Update Tool 1.3.14

OS, DB, other environment details and versions

Linux

Related area

-> Compilation

Related issue(s) (optional)

No response

Suggested label(s) (optional)

No response

Suggested assignee(s) (optional)

No response

@ballerina-bot ballerina-bot added needTriage The issue has to be inspected and labeled manually userCategory/Compilation labels May 7, 2023
@MaryamZi MaryamZi added Type/Question and removed Type/Bug needTriage The issue has to be inspected and labeled manually labels Feb 22, 2024
@MaryamZi
Copy link
Member

Since myconfig.bal is just another file in the same module, you don't have to use mymodule: to access the myconfig variable.

import ballerina/io;

public function main() {
    io:print(myconfig.port);
}

To move this to a different module, you need to add the module with

bal add myconfig

This will add the module in modules/myconfig. Once you move the config code to that module, you'll have to update the main.bal file to import the module.

import mymodule.myconfig;

import ballerina/io;

public function main() {
    io:print(myconfig:myconfig.port);
}

Note that you'll also have to update the Config.toml file.

[mymodule.myconfig]
myconfig.port = 8005

Also see https://ballerina.io/learn/organize-ballerina-code/

@MaryamZi MaryamZi added Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Team/jBallerina All the issues related to BIR, JVM backend code generation and runtime labels Feb 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Team/jBallerina All the issues related to BIR, JVM backend code generation and runtime Type/Question userCategory/Compilation
Projects
None yet
Development

No branches or pull requests

3 participants