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]: MelonPreferences LoadFromFile and SaveToFile does not generate Exception #328

Open
1 of 8 tasks
MeitziQ opened this issue Dec 7, 2022 · 0 comments
Open
1 of 8 tasks
Labels
Bug / Issue Something isn't working Work-in-Progress This issue or pull request is being worked on currently

Comments

@MeitziQ
Copy link

MeitziQ commented Dec 7, 2022

All of the following criteria must be met

  • All Requirements must be installed.
  • Full Latest.log file included. If no file exists then leave this unchecked and state so.

All of the following are optional to answer

  • Tried reinstalling the Game.
  • Tried reinstalling MelonLoader.
  • Tried restarting PC.
  • Was able to see the Start Screen.

Describe the issue.

When you are using MelonPreferences_Category methods LoadFromFile() and SaveToFile() you have no idea if they fail.
You can't fix or know situation where configuration files is broken and there is no real connection between file and mod anymore.

Example code:

using System;
using MelonLoader;
[assembly: MelonInfo(typeof(MelonTest.Main), "MelonTest", "0.2", "Me")]
namespace MelonTest {
    public class Main : MelonMod {
        private MelonPreferences_Category settingsCategory;
        private MelonPreferences_Entry<bool> modEnabled;
        public override void OnApplicationLateStart() {
            MelonLogger.Msg("Initializing settings..");
            settingsCategory = MelonPreferences.CreateCategory("OurFirstCategory");
            modEnabled = settingsCategory.CreateEntry<bool>("MODenabled", true, "", "break this file by setting this to example 'tre'");
            settingsCategory.SetFilePath("Mods/MelonTest.cfg", autoload: false);
            try {
                settingsCategory.LoadFromFile(); //This should generate Exception if load does not success. (or creating file first time does not success)
                settingsCategory.SaveToFile(); //This should generate Exception if saving does not happpen, but it does not
                MelonLogger.Msg("We got no errors. Value of modEnabled=" + modEnabled.Value.ToString());
            } catch (Exception exception) {
                MelonLogger.Msg("We got Exception: " + exception.ToString());
            }
        }       
    }   
}

After first run, corrupt cfg file somehow, example "MODenabled = tre" (real life scenario)
After this, there is no way know inside mod that file is corrupted.

Console will show:

[11:57:55.146] [MelonTest] Initializing settings..
[11:57:55.154] [MelonTest] [ERROR] Error while Loading Preferences from Mods/MelonTest.cfg: Tomlet.Exceptions.TomlInvalidValueException: Expected the start of a number, string literal, boolean, array, or table on line 3, found 't'

  at Tomlet.TomlParser.ReadValue (Tomlet.TomletStringReader reader) [0x002b9] in <239dd078bb4e49c8a1ff8200d76f2e32>:0 

  at Tomlet.TomlParser.ReadKeyValuePair (Tomlet.TomletStringReader reader, System.String& key, Tomlet.Models.TomlValue& value) [0x00045] in <239dd078bb4e49c8a1ff8200d76f2e32>:0 

  at Tomlet.TomlParser.Parse (System.String input) [0x0008c] in <239dd078bb4e49c8a1ff8200d76f2e32>:0 

  at Tomlet.TomlParser.ParseFile (System.String filePath) [0x0000c] in <239dd078bb4e49c8a1ff8200d76f2e32>:0 

  at MelonLoader.Preferences.IO.File.Load () [0x00017] in <239dd078bb4e49c8a1ff8200d76f2e32>:0 

  at MelonLoader.MelonPreferences.LoadFileAndRefreshCategories (MelonLoader.Preferences.IO.File file, System.Boolean printmsg) [0x00000] in <239dd078bb4e49c8a1ff8200d76f2e32>:0 
[11:57:55.155] [WARNING] Defaulting Mods/MelonTest.cfg to Fallback Functionality to further avoid File Corruption...
[11:57:55.156] [MelonTest] MelonPreferences Saved to Mods/MelonTest.cfg
[11:57:55.157] [MelonTest] We got no errors. Value of modEnabled=True

Please notice line "[MelonTest] MelonPreferences Saved to Mods/MelonTest.cfg" which is not incorrect. It is not true.
But in code, no errors all.
Expected result is raised Exception which would allow fix situation.

Did you attach your log file?

  • Yes, I attached my log file to the text box above.
  • No, I could not find a log file at {Game_Directory}\MelonLoader\Latest.log
@HerpDerpinstine HerpDerpinstine added Bug / Issue Something isn't working Work-in-Progress This issue or pull request is being worked on currently labels Jan 9, 2023
@HerpDerpinstine HerpDerpinstine added this to the 0.6.1 milestone Jan 9, 2023
@HerpDerpinstine HerpDerpinstine modified the milestones: 0.6.1, 0.6.2 Jul 12, 2023
@HerpDerpinstine HerpDerpinstine removed this from the 0.6.2 milestone Oct 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug / Issue Something isn't working Work-in-Progress This issue or pull request is being worked on currently
Projects
None yet
Development

No branches or pull requests

2 participants