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

Not finding settings that exist #245

Open
ventsyv opened this issue Sep 6, 2024 · 1 comment
Open

Not finding settings that exist #245

ventsyv opened this issue Sep 6, 2024 · 1 comment

Comments

@ventsyv
Copy link

ventsyv commented Sep 6, 2024

A piece of code that works perfectly fine with libConfig 1.7.2 is failing to find the config settings when running with libConfig 1.7.3

Here is a simplified example. I haven't tested it (the example) but I'm fairly certain this will throw SettingNotFound exception:

bool myFunc(const libconfig::Settings& root)
{
	string name = "MySetting";
	string location = "";
	uint32_t value = 0;
	
	try
	{
		const libConfig::Settings& settings = root.lookup(location);
		if (! settings.lookupValue(name, value) )
			return false;
	}
	catch (libConfig::SettingNotFoundException& x)
	{
		//log
		return false;
	}
	catch (libConfig::SettingNotFoundException& x)
	{
		//log
		return false;
	}
	
	cout<<"Value is: " << value <<endl;
	
	
}

The config file looks like this:


#************ HEADER **********
# Some comment 1
# Some comment 2
#*******************************
 
# Another comment
MySetting = 25;

I'll try to debug it a bit more later and might be able to contribute a fix, but it will be appreciated if someone familiar with the code can look at a diff between the 2 versions and see if there is anything obvious.
I looked at the diff myself but don't see anything that can cause this.

@hyperrealm
Copy link
Owner

You were relying on a bug that has been fixed. Empty string is not a valid path.

Your code (in the try block) should be:

value = root.lookup(name);

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

No branches or pull requests

2 participants