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 report) 0.48 beta: errors with backend API "get" methods #2230

Closed
1 task done
mabeyj opened this issue Oct 14, 2021 · 1 comment
Closed
1 task done

(Bug report) 0.48 beta: errors with backend API "get" methods #2230

mabeyj opened this issue Oct 14, 2021 · 1 comment

Comments

@mabeyj
Copy link

mabeyj commented Oct 14, 2021

Preflight Checklist

  • I have searched the issue tracker for a bug report that matches the one I want to file, without success.

Trilium Version

0.48.1-beta

What operating system are you using?

Windows

What is your setup?

Local (no sync)

Operating System Version

Windows 10 21H1

Expected Behavior

The backend api.getNote, api.getBranch, and api.getAttribute methods shouldn't cause an error.

Actual Behavior

Create a JS frontend code note:

(async () => {
    const result = await api.runOnBackend(noteId => {
        return api.getNote(noteId);
    }, [api.currentNote.noteId]);
    console.log(result);
})();

Open the dev console, execute the script, and an error occurs: Error: server error: Load of script note "<note title>" (<note id>) failed with: Cannot read property '<note id>' of undefined"

Similarly, api.getBranch and api.getAttribute also cause errors.

Additional Information

Replacing api.getNote with becca.getNote works (as well as becca.getBranch and becca.getAttribute).

The issue seems to be these three methods on BackendScriptApi are assigned their respective becca methods, and the becca methods use this which is undefined when the backend methods are called:

this.getNote = becca.getNote;
/**
* @method
* @param {string} branchId
* @returns {Branch|null}
*/
this.getBranch = becca.getBranch;
/**
* @method
* @param {string} attributeId
* @returns {Attribute|null}
*/
this.getAttribute = becca.getAttribute;

@zadam
Copy link
Owner

zadam commented Oct 14, 2021

Hi, thanks for report, fixed.

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

No branches or pull requests

2 participants