Skip to content

[Bug]: Unable to use masscode #592

Closed

Description

@MustCodeAl

Describe the bug

Not able to create any snippets or folders and cant migrate from previous masscode 3 snippets

To reproduce

  1. Go to ... file
  2. Click on ... create a new snippet folder etc,
  3. Scroll down to ..
  4. nothing is made

Version

masscode 4.0.0

OS

macOS 15.6.1 Sequoia M1

Validations

Activity

  1. BePo65 commented on Sep 28, 2025

    @BePo65

    Same with me on my windows 11 system. Shows the following error message for about 1s (at the right bottom corner of the window).

    Perhaps it would also be a good idea to give a short hint on how to migrate from an older version in the github readme file and/or the documentation.

    Image

  2. antonreshetov commented on Sep 28, 2025

    @antonreshetov
    Member

    @BePo65 The migration should happen without any action on the user's part, so there's no point in giving any hints.

    I can't reproduce the bug yet. Are you sure you are using the correct .json file from the old version of the application for migration?

  3. pa-0 commented on Sep 28, 2025

    @pa-0

    The migration worked without a hitch for me. Then, on restart, massCode was empty (0 snippets). On second restart of the app, however, the issue seems to have resolved itself. Hopefully others will find the same to be true.

  4. BePo65 commented on Sep 28, 2025

    @BePo65

    On my 1st try to update from massCode v3 to v4 I was using winget in UnigetUI. So just to be sure that this is not a problem of winget, I went back to massCode 3.12.1; all my snippets were still there. The settings were like that:

    Image

    After that I followed these steps:

    1. download massCode installer from github ('massCode.Setup.4.0.0.exe')
    2. started this installer
    3. at the end of the installation process used the 'start massCode' option
    4. massCode started; as expected; no automatic migration of the existing snippets happened; massCode contained no snippets.
    5. went to preferences to start the manual migration

    Image

    1. selected the db.json file (only json files can be selected although the text in the preferences says 'select a folder')

    Image

    1. pressed select; file selection dialog closed; preferences were visible again; in the right bottom corner an error was displayed saying 'sqllite error: file is not a database'

    Image

    The db.json file contains the snippets from massCode 3.12 and looks like this:

    Image

    What am I doing wrong?

  5. mikeingz commented on Sep 29, 2025

    @mikeingz

    On my 1st try to update from massCode v3 to v4 I was using winget in UnigetUI. So just to be sure that this is not a problem of winget, I went back to massCode 3.12.1; all my snippets were still there. The settings were like that:

    I have the exact same issue. I am on Windows 11 too.
    I can't even create a new snippet.

    When I open the Devtools, I can see these server errors :

    Image
  6. BePo65 commented on Sep 29, 2025

    @BePo65

    The same happens on my system: I cqn neither add a folder nor a new snippet.

    My configuration:

    • Windows 11 pro
    • massCode installation for 'current user' (not for all users)
  7. antonreshetov commented on Sep 29, 2025

    @antonreshetov
    Member

    For testing, I can only use Win 10, and the application launched correctly on my PC. I can assume that sqlite3 does not launch on some platforms, including Win 11, although there is confirmation that the application works correctly on Win 11. Try building the application locally with pnpm install, pnpm run build.

  8. antonreshetov commented on Sep 29, 2025

    @antonreshetov
    Member
  9. BePo65 commented on Sep 29, 2025

    @BePo65

    Which one: 'massCode-4.0.1.exe' or 'massCode.4.0.1.exe'

  10. antonreshetov commented on Sep 29, 2025

    @antonreshetov
    Member

    @BePo65 According to SHA256, these are identical files. For some reason, they were attached to the release in the workflow. So any of them can be run.

  11. mikeingz commented on Sep 29, 2025

    @mikeingz

    still the same issue with 4.0.1

  12. antonreshetov commented on Sep 29, 2025

    @antonreshetov
    Member

    Unfortunately, I can't help you at the moment. It seems to be a specific problem.

  13. emoveo-design commented on Sep 29, 2025

    @emoveo-design

    Hello there 👋
    Same problem on my M4 macBook using Sequoia 15.7
    I just downloaded the 4.0.1 version and when i try migrating i get an error, but not quite the same

    Image

  14. BePo65 commented on Sep 29, 2025

    @BePo65

    Even on my system 4.0.1 didn't change anything. I cloned the repo and would try to track the problem down (if this would help you).

    Before I spend to much time looking for the method that imports the v3 snippets: do you have a hint for me, where to look?

  15. 4 remaining items

  16. antonreshetov commented on Sep 29, 2025

    @antonreshetov
    Member

    @BePo65 the project uses

    "node": "20.16.0"

  17. subfighter3 commented on Sep 29, 2025

    @subfighter3

    @emoveo-design Judging by the error, you have a non-unique name tag in db.json.

    I tried to get rid of non-unique tag names, but now I got a different error when trying to migrate from v3: Error invoking remote method 'db:migrate': SqliteError: NOT NULL constraint failed: snippets.createdAt.

    MassCode v4.0.1 on M4 Taohe

  18. antonreshetov commented on Sep 29, 2025

    @antonreshetov
    Member

    @subfighter3

    The error is quite clear: NOT NULL constraint failed: snippets.createdAt.
    This means some of your snippets don’t have a createdAt field, which causes the migration to fail.

    I’m building this project alone, so please try to troubleshoot issues like this on your side first — often the error message already points to the root cause. If it still doesn’t work after checking, feel free to open an issue with more details.

  19. subfighter3 commented on Sep 29, 2025

    @subfighter3

    @subfighter3
    The error is quite clear: NOT NULL constraint failed: snippets.createdAt. This means some of your snippets don’t have a createdAt field, which causes the migration to fail.

    Of course, you are right, I digged into the JSON and found some "createdAt": null, where I pasted the updatedAt value instead of null, then the migration was done successfully.

    Thanks a lot for the insight

  20. antonreshetov commented on Sep 29, 2025

    @antonreshetov
    Member

    @subfighter3 I will take such cases into account and make workarounds in migration.

  21. BePo65 commented on Sep 29, 2025

    @BePo65

    What I did:

    1. switched to node v24
    2. deleted directory node_modules
    3. pnpm install; this recreated better-sqlite3 and electron
    4. pnpm run dev
    5. message saying something like 'db is not a database'; terminated program
    6. moved files in my massCode data directory (C:\Users\Berni\massCode) to a temporary folder
    7. pnpm run dev showed that a new database is created; in the preferences I could migrate the old snippets; in the app I could create folders and snippets.
    8. switched back to node lts (v22) and ran installed version of massCode (v4) -> I could import my snippets from v3, create new snippets and folders -> everything is fine again.

    What I was learning:

    Deleting the masscode.db file in the massCode data directory solved my problems.

    • my problem was not that the sqlite server did not start, but that massCode v4 tried to use the database masscode.db that was present in my massCode v3 data directory (the file originated from 2022, so it cannot be a fragment of one of my updates to v4). Deleting this file solved my problems.

    So thanks to @antonreshetov for the ultra fast responses and for this great tool. The problem is solved for me.

  22. mikeingz commented on Sep 30, 2025

    @mikeingz

    I confirm that deleting masscode.db also solved it for me.

  23. antonreshetov commented on Sep 30, 2025

    @antonreshetov
    Member

    @BePo65 Wow, thanks for the research, now I understand what's going on. Actually, the masscode.db file is a database from https://github.com/louischatriot/nedb that was used in massCode v1. And now in v4, which uses sqlite3, the name coincides in case-insensitive OSes: masscode.db and massСode.db. This is a real jackpot 😄 It was so long ago that I forgot I even used nedb ) Going to fix it.

  24. antonreshetov commented on Sep 30, 2025

    @antonreshetov
    Member

    Fixed #601

  25. MustCodeAl commented on Oct 3, 2025

    @MustCodeAl
    Author

    What I did:

    1. switched to node v24
    2. deleted directory node_modules
    3. pnpm install; this recreated better-sqlite3 and electron
    4. pnpm run dev
    5. message saying something like 'db is not a database'; terminated program
    6. moved files in my massCode data directory (C:\Users\Berni\massCode) to a temporary folder
    7. pnpm run dev showed that a new database is created; in the preferences I could migrate the old snippets; in the app I could create folders and snippets.
    8. switched back to node lts (v22) and ran installed version of massCode (v4) -> I could import my snippets from v3, create new snippets and folders -> everything is fine again.

    What I was learning:

    Deleting the masscode.db file in the massCode data directory solved my problems.

    • my problem was not that the sqlite server did not start, but that massCode v4 tried to use the database masscode.db that was present in my massCode v3 data directory (the file originated from 2022, so it cannot be a fragment of one of my updates to v4). Deleting this file solved my problems.

    So thanks to @antonreshetov for the ultra fast responses and for this great tool. The problem is solved for me.

    this worked, thank you

  26. LadyNay commented on Jun 20, 2026

    @LadyNay

    A python script to fix the issue

    #!/usr/bin/env python3
    """
    Fix massCode v3 db.json for v4 migration.
    
    v4 SQLite enforces UNIQUE on tags.name. v3 allowed duplicate tag names
    (often from accidentally tagging code selections). This script deduplicates
    tags and remaps snippet tag references.
    """
    
    import json
    import sys
    from copy import deepcopy
    from pathlib import Path
    
    
    def fix_tags(data: dict) -> tuple[dict, dict]:
        data = deepcopy(data)
        tags = data.get("tags", [])
    
        name_to_id: dict[str, str] = {}
        id_remap: dict[str, str] = {}
        kept_tags = []
        duplicates_removed = 0
    
        for tag in tags:
            tag_id = tag.get("id")
            name = tag.get("name") or ""
    
            if name in name_to_id:
                id_remap[tag_id] = name_to_id[name]
                duplicates_removed += 1
                continue
    
            name_to_id[name] = tag_id
            id_remap[tag_id] = tag_id
            kept_tags.append(tag)
    
        data["tags"] = kept_tags
    
        snippets_updated = 0
        for snippet in data.get("snippets", []):
            tag_ids = snippet.get("tagsIds")
            if not tag_ids:
                continue
    
            seen = set()
            new_ids = []
            for old_id in tag_ids:
                new_id = id_remap.get(old_id, old_id)
                if new_id not in seen:
                    seen.add(new_id)
                    new_ids.append(new_id)
    
            if new_ids != tag_ids:
                snippets_updated += 1
            snippet["tagsIds"] = new_ids
    
        stats = {
            "original_tags": len(tags),
            "kept_tags": len(kept_tags),
            "duplicates_removed": duplicates_removed,
            "unique_names": len(name_to_id),
            "snippets_updated": snippets_updated,
        }
        return data, stats
    
    
    def main() -> None:
        input_path = Path(sys.argv[1]) if len(sys.argv) > 1 else Path(__file__).parent / "db.json"
        output_path = (
            Path(sys.argv[2])
            if len(sys.argv) > 2
            else input_path.with_name(input_path.stem + "_fixed.json")
        )
    
        with open(input_path, encoding="utf-8") as f:
            data = json.load(f)
    
        fixed, stats = fix_tags(data)
    
        with open(output_path, "w", encoding="utf-8") as f:
            json.dump(fixed, f, ensure_ascii=False, indent=2)
    
        print(f"Input:  {input_path}")
        print(f"Output: {output_path}")
        print(f"Tags:   {stats['original_tags']} -> {stats['kept_tags']} ({stats['duplicates_removed']} duplicates removed)")
        print(f"Snippets with remapped tag refs: {stats['snippets_updated']}")
        print("\nImport the *_fixed.json folder in massCode v4: Settings -> Storage -> From massCode v3")
    
    
    if __name__ == "__main__":
        main()
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions