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

TG Error: Cannot read properties of undefined (reading 'isMap') on mobile #307

Open
Fertion opened this issue Aug 5, 2024 · 8 comments
Open

Comments

@Fertion
Copy link

Fertion commented Aug 5, 2024

The error occurs when I make a request to https://openrouter.ai/api/v1/chat/completions with the API key on an Android mobile device. Everything is set up exactly the same on the computer, and it works. Initially, I just copied the plugin folder into the mobile Obsidian config and tried to run it, but this error appeared. Then I deleted the plugin and installed it from scratch, entering all the settings - the result is the same. According to openrouter.ai, I can see that the request is reaching the server, and tokens are being consumed. If I set a different provider, it works on the mobile device.
image

@calmwaves111
Copy link

calmwaves111 commented Aug 28, 2024

me too, i use https://open.bigmodel.cn/api/paas/v4/chat/completions

android 12,obsidian 1.6.7

@akaihola
Copy link

akaihola commented Sep 7, 2024

Looking at the source code, isMap is only mentioned in these two files:

src/helpers/javascript-sandbox.ts#L17

 17 import { isMap, isSet } from "util/types";
 18 import Read from "#/extractors";

 42     splitters: langchain.splitters,
 43     isMap,
 44     isSet,

src/helpers/handlebars-helpers.ts#L22

 21 } from "#/extractors/content-extractor";
 22 import { isMap, isSet } from "util/types";
 23 import Read from "#/extractors";

121           }
122         } else if (isMap(context)) {
123           const j = context.size;

#175 looks a bit similar, and is marked Won't Fix. Also, @BlaisePx used ADB to get to the browser console to get a full traceback. I've never done that, so need to research the steps needed.

The error text cannot read properties of I can't find in Text Generator source code, nor in any of the repositories of the obsidianmd organization.

I'm not a JavaScript guru, so this is how far I got while trying to help by taking a look at the problem.

@akaihola
Copy link

akaihola commented Sep 7, 2024

I managed to get to the Obsidian app console through ADB (using chrome://inspect), and see the traceback attached. Looking at the debugger on the line at IX (plugin:obsidian-textgenerator-plugin:1805:16563), the JavaScript code seems to match the original TypeScript in src/helpers/javascript-sandbox.ts#L43:

    async function IX(I, e) {
        let t, l = {
            JSON5: WTe.default,
            lodashGet: hTe.default,
            lodashSet: ZTe.default,
            pluginApi: IU,
            Notice: bue.Notice,
            pull: Hz,
            langchain: hde,
            splitters: Wy,
            isMap: dM.isMap,    // <-- this seems to be the problem
            isSet: dM.isSet,
            globalThis: {},
            ...e,

Here's the traceback:

app.js:1 Capacitor plugin "Keyboard" already registered. Cannot register plugins twice.
T.m @ app.js:1
/favicon.ico:1 
        
        
       Failed to load resource: the server responded with a status of 404 (Not Found)
app.js:1 Obsidian Developer Console
plugin:review-obsidian:856 Loading the Review plugin v1.6.5.
plugin:leader-hotkeys-obsidian:1006  Leader Hotkeys: Started Loading.
plugin:leader-hotkeys-obsidian:1006  Leader Hotkeys: Loading previously saved settings.
plugin:leader-hotkeys-obsidian:1006  Leader Hotkeys: Loaded previous settings.
plugin:leader-hotkeys-obsidian:1006  Leader Hotkeys: Registering necessary event callbacks
plugin:leader-hotkeys-obsidian:1006  Leader Hotkeys: Registered workspace "keydown" event callbacks.
plugin:leader-hotkeys-obsidian:1006  Leader Hotkeys: Registered open modal command
plugin:leader-hotkeys-obsidian:1006  Leader Hotkeys: Registered Setting Tab.
plugin:leader-hotkeys-obsidian:1006  Leader Hotkeys: Finished Loading.
plugin:emacs-text-editor:54 loading plugin: Emacs text editor
plugin:url-into-selection:690 loading url-into-selection
plugin:obsidian-textgenerator-plugin:2098 attempting to get files 30
plugin:obsidian-textgenerator-plugin:1999 Object
plugin:obsidian-textgenerator-plugin:1997 calling stream generate
plugin:obsidian-textgenerator-plugin:1997 the request Object
plugin:obsidian-textgenerator-plugin:2098 TypeError: Cannot read properties of undefined (reading 'isMap')
    at IX (plugin:obsidian-textgenerator-plugin:1805:16563)
    at I.request (plugin:obsidian-textgenerator-plugin:1958:70)
    at async eval (plugin:obsidian-textgenerator-plugin:1962:422)
handelError @ plugin:obsidian-textgenerator-plugin:2098
plugin:obsidian-textgenerator-plugin:2098 TypeError: Cannot read properties of undefined (reading 'isMap')
    at IX (plugin:obsidian-textgenerator-plugin:1805:16563)
    at I.request (plugin:obsidian-textgenerator-plugin:1958:70)
    at async eval (plugin:obsidian-textgenerator-plugin:1962:422)
handelError @ plugin:obsidian-textgenerator-plugin:2098
plugin:obsidian-textgenerator-plugin:1999 Object
plugin:obsidian-textgenerator-plugin:1997 calling stream generate
plugin:obsidian-textgenerator-plugin:1997 the request Object
plugin:obsidian-textgenerator-plugin:2098 TypeError: Cannot read properties of undefined (reading 'isMap')
    at IX (plugin:obsidian-textgenerator-plugin:1805:16563)
    at I.request (plugin:obsidian-textgenerator-plugin:1958:70)
    at async eval (plugin:obsidian-textgenerator-plugin:1962:422)
handelError @ plugin:obsidian-textgenerator-plugin:2098
plugin:obsidian-textgenerator-plugin:2098 TypeError: Cannot read properties of undefined (reading 'isMap')
    at IX (plugin:obsidian-textgenerator-plugin:1805:16563)
    at I.request (plugin:obsidian-textgenerator-plugin:1958:70)
    at async eval (plugin:obsidian-textgenerator-plugin:1962:422)
handelError @ plugin:obsidian-textgenerator-plugin:2098
plugin:obsidian-textgenerator-plugin:1999 Object
plugin:obsidian-textgenerator-plugin:1997 calling stream generate
plugin:obsidian-textgenerator-plugin:1997 the request Object
plugin:obsidian-textgenerator-plugin:2098 TypeError: Cannot read properties of undefined (reading 'isMap')
    at IX (plugin:obsidian-textgenerator-plugin:1805:16563)
    at c.request (plugin:obsidian-textgenerator-plugin:1958:70)
    at async eval (plugin:obsidian-textgenerator-plugin:1962:422)
handelError @ plugin:obsidian-textgenerator-plugin:2098
plugin:obsidian-textgenerator-plugin:2098 TypeError: Cannot read properties of undefined (reading 'isMap')
    at IX (plugin:obsidian-textgenerator-plugin:1805:16563)
    at c.request (plugin:obsidian-textgenerator-plugin:1958:70)
    at async eval (plugin:obsidian-textgenerator-plugin:1962:422)
handelError @ plugin:obsidian-textgenerator-plugin:2098
plugin:obsidian-textgenerator-plugin:1999 Object
plugin:obsidian-textgenerator-plugin:1997 calling stream generate
plugin:obsidian-textgenerator-plugin:1997 the request Object
plugin:obsidian-textgenerator-plugin:2098 TypeError: Cannot read properties of undefined (reading 'isMap')
    at IX (plugin:obsidian-textgenerator-plugin:1805:16563)
    at c.request (plugin:obsidian-textgenerator-plugin:1958:70)
    at async eval (plugin:obsidian-textgenerator-plugin:1962:422)
handelError @ plugin:obsidian-textgenerator-plugin:2098
plugin:obsidian-textgenerator-plugin:2098 TypeError: Cannot read properties of undefined (reading 'isMap')
    at IX (plugin:obsidian-textgenerator-plugin:1805:16563)
    at c.request (plugin:obsidian-textgenerator-plugin:1958:70)
    at async eval (plugin:obsidian-textgenerator-plugin:1962:422)
handelError @ plugin:obsidian-textgenerator-plugin:2098
plugin:obsidian-textgenerator-plugin:1999 Object
plugin:obsidian-textgenerator-plugin:1997 calling stream generate
plugin:obsidian-textgenerator-plugin:1997 the request Object
plugin:obsidian-textgenerator-plugin:2098 TypeError: Cannot read properties of undefined (reading 'isMap')
    at IX (plugin:obsidian-textgenerator-plugin:1805:16563)
    at c.request (plugin:obsidian-textgenerator-plugin:1958:70)
    at async eval (plugin:obsidian-textgenerator-plugin:1962:422)
handelError @ plugin:obsidian-textgenerator-plugin:2098
plugin:obsidian-textgenerator-plugin:2098 TypeError: Cannot read properties of undefined (reading 'isMap')
    at IX (plugin:obsidian-textgenerator-plugin:1805:16563)
    at c.request (plugin:obsidian-textgenerator-plugin:1958:70)
    at async eval (plugin:obsidian-textgenerator-plugin:1962:422)
handelError @ plugin:obsidian-textgenerator-plugin:2098
plugin:obsidian-textgenerator-plugin:1999 {customContext: undefined, context: {}}
plugin:obsidian-textgenerator-plugin:1997 calling stream generate
plugin:obsidian-textgenerator-plugin:1997 the request {request: Request}
plugin:obsidian-textgenerator-plugin:2098 TypeError: Cannot read properties of undefined (reading 'isMap')
    at IX (plugin:obsidian-textgenerator-plugin:1805:16563)
    at c.request (plugin:obsidian-textgenerator-plugin:1958:70)
    at async eval (plugin:obsidian-textgenerator-plugin:1962:422)
handelError @ plugin:obsidian-textgenerator-plugin:2098
generateStreamInEditor @ plugin:obsidian-textgenerator-plugin:2002
await in generateStreamInEditor
generateInEditor @ plugin:obsidian-textgenerator-plugin:2002
eval @ plugin:obsidian-textgenerator-plugin:2093
(anonymous) @ app.js:1
e.handleEvent @ app.js:1
plugin:obsidian-textgenerator-plugin:2098 TypeError: Cannot read properties of undefined (reading 'isMap')
    at IX (plugin:obsidian-textgenerator-plugin:1805:16563)
    at c.request (plugin:obsidian-textgenerator-plugin:1958:70)
    at async eval (plugin:obsidian-textgenerator-plugin:1962:422)
handelError @ plugin:obsidian-textgenerator-plugin:2098
eval @ plugin:obsidian-textgenerator-plugin:2093
await in eval
(anonymous) @ app.js:1
e.handleEvent @ app.js:1

@akaihola
Copy link

akaihola commented Sep 7, 2024

In the compiled JavaScript, I see

var dM = require("util/types");

So does this mean that require somehow fails and dM is left undefined?

Indeed, when I drop into the debugger, I see:
image

@lylewinton
Copy link

I get the same error message, but for me occurs if I use a {{#script}}...{{/script}} block anywhere within a template and while on Android. It works fine on a PC. The code I was trying to run was simply an "await gen(prompt,{})" call, but this error occurs even if the block contains basic javascript (no calls) or even with no javascript at all, And it halts any further processing once it hits that block.

android 10,obsidian 1.6.7, text generator 0.7.37

@akaihola
Copy link

I'm assuming the require happens so early in the Obsidian app's WebView initialization that it's hard to get the debugger attached and see what goes wrong. I wonder if the app could be configured to save log entries and JavaScript exceptions on the phone for later inspection.

@haouarihk
Copy link
Collaborator

The bug should be fixed.
can someone test with version 0.7.43

Thanks for reporting the bug and sorry for the late fix

@hughengwu
Copy link

I tested version 0.7.43 on Android, but it still cannot run properly. The error message is: TG Error: process is not defined.

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

6 participants