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

GM.xmlHttpRequest.onerror causes uncaught exception when logging error #2158

Closed
adamlui opened this issue Aug 17, 2024 · 7 comments
Closed

Comments

@adamlui
Copy link

adamlui commented Aug 17, 2024

(Please fill out the issue template with your details)

Expected Behavior

Log the error, do not throw

Actual Behavior

Uncaught TypeError: can't convert label to string

Specifications

  • Firefox: 129.0.1 (64-bit)
  • TM: v5.1.1
  • OS: Win10 Home

Script

(Please give an example of the script if applicable.)

...
function consoleErr(label, msg) { console.error(`${config.appSymbol} ${config.appName} » ${label}${ msg ? `: ${msg}` : '' }`)}

GM.xmlHttpRequest({
    method: apis[get.reply.api].method,
    url: apis[get.reply.api].endpoints?.completions || apis[get.reply.api].endpoint,
    responseType: config.streamingDisabled || !config.proxyAPIenabled ? 'text' : 'stream',
    headers: api.createHeaders(get.reply.api), data: api.createPayload(get.reply.api, msgChain),
    onload: resp => dataProcess.text(get.reply, resp),
    onloadstart: resp => dataProcess.stream(get.reply, resp),
    onerror: err => { consoleErr(err)
        if (!config.proxyAPIenabled) appAlert(!config.openAIkey ? 'login' : ['openAInotWorking', 'suggestProxy'])
        else if (get.reply.status != 'done') api.tryNew(get.reply)
    }
})
...

The above on error will throw unless err is wrapped in JSON.stringify()

image

(In Violentmonkey it does not throw + properly logs the err obj and script healthily keeps on running)

image

Maybe related to #1877

@adamlui
Copy link
Author

adamlui commented Aug 17, 2024

I fixed the throwing by updating consoleErr() to:

function consoleErr(label, msg) {
    console.error( `${config.appSymbol} ${config.appName} » ${
        typeof label == 'object' ? JSON.stringify(label) : label }${ msg ? `: ${msg}` : ''}`)
}

... but it's still nice how VM auto-converts, also for some reason their obj is much more detailed

TM:

image

VM:

image

adamlui added a commit to adamlui/ai-web-extensions that referenced this issue Aug 17, 2024
adamlui added a commit to KudoAI/amazongpt that referenced this issue Aug 17, 2024
adamlui added a commit to KudoAI/googlegpt that referenced this issue Aug 17, 2024
adamlui added a commit to KudoAI/bravegpt that referenced this issue Aug 17, 2024
adamlui added a commit to KudoAI/duckduckgpt that referenced this issue Aug 17, 2024
adamlui added a commit to adamlui/userscripts that referenced this issue Aug 17, 2024
…s in TM (Tampermonkey/tampermonkey#2158) ↞ [auto-sync from `adamlui/chatgpt-apps/amazongpt`]
adamlui added a commit to adamlui/userscripts that referenced this issue Aug 17, 2024
…s in TM (Tampermonkey/tampermonkey#2158) ↞ [auto-sync from `adamlui/chatgpt-apps/googlegpt`]
adamlui added a commit to adamlui/userscripts that referenced this issue Aug 17, 2024
…s in TM (Tampermonkey/tampermonkey#2158) ↞ [auto-sync from `adamlui/chatgpt-apps/duckduckgpt`]
adamlui added a commit to adamlui/userscripts that referenced this issue Aug 17, 2024
adamlui added a commit to adamlui/ai-web-extensions that referenced this issue Aug 24, 2024
adamlui added a commit to KudoAI/duckduckgpt that referenced this issue Aug 24, 2024
adamlui added a commit to KudoAI/bravegpt that referenced this issue Aug 24, 2024
adamlui added a commit to KudoAI/amazongpt that referenced this issue Aug 24, 2024
adamlui added a commit to KudoAI/googlegpt that referenced this issue Aug 24, 2024
adamlui added a commit to adamlui/userscripts that referenced this issue Aug 24, 2024
…in TM (Tampermonkey/tampermonkey#2158) ↞ [auto-sync from `adamlui/chatgpt-apps/duckduckgpt`]
adamlui added a commit to adamlui/userscripts that referenced this issue Aug 24, 2024
adamlui added a commit to adamlui/userscripts that referenced this issue Aug 24, 2024
adamlui added a commit to adamlui/userscripts that referenced this issue Aug 24, 2024
@derjanb
Copy link
Member

derjanb commented Aug 29, 2024

Will be fixed at the next BETA version. Thanks for reporting.

Out of curiosity, the following test script is always logging [object Object] here. With no browser or script manager I get the stringified object logged.

image

// ==UserScript==
// @name         234234.example.com
// @namespace    http://tampermonkey.net/
// @version      2024-08-29
// @description  try to take over the world!
// @author       You
// @match        https://*/*
// @grant        GM.xmlHttpRequest
// @connect      example.com
// ==/UserScript==

function consoleErr(label, msg) { console.error(`aa bb » ${label}${ msg ? `: ${msg}` : '' }`)}

GM.xmlHttpRequest({
    method: "GET",
    url: "https://234234.example.com",
    onerror: function(e) {
      consoleErr(e);
    }
});

@adamlui
Copy link
Author

adamlui commented Aug 29, 2024

What's no browser or script manager mean? Also the code in FF TM shows the original TypeError to me

@derjanb
Copy link
Member

derjanb commented Aug 29, 2024

You said "in Violentmonkey it does not throw + properly logs the err obj". What does "properly" mean? I only get the string [object Object] being logged.

@derjanb derjanb added this to the 5.3 milestone Aug 29, 2024
@adamlui
Copy link
Author

adamlui commented Aug 30, 2024

You said "in Violentmonkey it does not throw + properly logs the err obj". What does "properly" mean? I only get the string [object Object] being logged.

I get the pic I pasted
358860236-b6c362bd-56c8-47e8-b191-60994e3483e7

Also my code is:

                onerror: err => { log.err(err)
                    if (!config.proxyAPIenabled) appAlert(!config.openAIkey ? 'login' : ['openAInotWorking', 'suggestProxy'])
                    else if (get.reply.status != 'done') api.tryNew(get.reply)
                }

... and I notice on error, it logs only, the next 2 lines don't run

image

When I simplify the onerror to just api.tryNew(get.reply) it works though

@adamlui
Copy link
Author

adamlui commented Aug 30, 2024

I figured it out, the stream is considered done by the reader on error so i removed the condition

@derjanb
Copy link
Member

derjanb commented Sep 5, 2024

Should be fixed at 5.3.6209 (crx|xpi in review)

Please download the crx file linked above and drag and drop it to the extensions page chrome://extensions (after you've enabled 'Developer Mode').

For a quick fix please export your settings and scripts as zip or (JSON) file at the "Utilities" tab and import it back at the fixed BETA version.

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