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

Unhandled Promise Rejection: Error: key does not exist #9

Open
jedfonner opened this issue Oct 15, 2023 · 4 comments
Open

Unhandled Promise Rejection: Error: key does not exist #9

jedfonner opened this issue Oct 15, 2023 · 4 comments

Comments

@jedfonner
Copy link

I have a pretty straightforward store using SettingsManager but I am getting an unhandled promise rejection saying the key does not exist

import { SettingsManager } from 'tauri-settings';
import { writable } from 'svelte/store';

type SettingsSchema = {
	rootFolder: string;
};

const settingsManager = new SettingsManager<SettingsSchema>(
	{
		rootFolder: ''
	},
	{ fileName: 'rootfolder.json' }
);

const store = writable(
	{
		rootFolder: ''
	},
	() => {
		settingsManager.initialize().then(async () => {
			console.log('Setting Manager initialized');
                        /* Error thrown on the next line */
			const rootFolderVal = await settingsManager.get('rootFolder');
			store.set({ rootFolder: rootFolderVal });
		});
	}
);

const setRootFolder = async (value: string) => {
	await settingsManager.set('rootFolder', value);
	store.update((s) => {
		s['rootFolder'] = value;
		return s;
	});
};

export default {
	subscribe: store.subscribe,
	setRootFolder
};

I thought that initializing the SettingsManager instance would make it so the key exists.
I worry this is a problem with my tauri app not being able to write to disk, but my tauri.conf.json has

"tauri": {
		"allowlist": {
			...
			"fs": {
				"all": true,
				"scope": ["**", "$APPCONFIG", "$APPCONFIG/*"]
			},
                        ...
			"path": {
				"all": true
			},
			...
		},
@harshkhandeparkar
Copy link
Owner

Can you check the contents of the settings json file?

@jedfonner
Copy link
Author

I ended up replacing my usage of tauri-settings with a simple class that reads and writes using https://tauri.app/v1/api/js/fs

@ragunathjawahar
Copy link

I ran into a similar problem and ended up removing this library from the project. But maybe it is a scope issue.

The following snippet is an excerpt from the OP,

"scope": ["**", "$APPCONFIG", "$APPCONFIG/*"]

My scope used to look like this, but I believe the scope should also include the APPDATA directory.

"scope": ["**", "$APPCONFIG", "$APPCONFIG/*", "$APPDATA", "$APPDATA/*"]

This is not a verified fix. Will comment after I try this solution on my project.

@harshkhandeparkar
Copy link
Owner

I ran into a similar problem and ended up removing this library from the project. But maybe it is a scope issue.

The following snippet is an excerpt from the OP,

"scope": ["**", "$APPCONFIG", "$APPCONFIG/*"]

My scope used to look like this, but I believe the scope should also include the APPDATA directory.

"scope": ["**", "$APPCONFIG", "$APPCONFIG/*", "$APPDATA", "$APPDATA/*"]

This is not a verified fix. Will comment after I try this solution on my project.

Sorry for the late reply. Can you please check and let me know whether adding APPDATA to the scope fixes it? Also, which operating system and Tauri API version are you using?

I am working on a rewrite of the library, which will use a Rust plugin instead, so the JS API will not be required at all. Hopefully, that will fix such issues in the future.

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

3 participants