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

Using console log in global scope crashes the execution #160

Open
OlegGulevskyy opened this issue Jul 26, 2022 · 3 comments
Open

Using console log in global scope crashes the execution #160

OlegGulevskyy opened this issue Jul 26, 2022 · 3 comments

Comments

@OlegGulevskyy
Copy link

Any time any console logs are attempted, it crashes the execution context.
Here is minimum reproducable code:

import alfy from "alfy";

const data = await alfy.fetch("https://jsonplaceholder.typicode.com/posts");
// alfy.log("DATA", data);

// alfy.log("HELLO");

const items = alfy
  .inputMatches(data, "title")
  .map((el) => ({ title: el.title, subtitle: el.subtitle, arg: el.id }));

alfy.output(items);

Uncomment any console log line and I am getting this crash

[18:37:21.238] TEST_WF[Script Filter] Queuing argument 'r'
[18:37:21.648] TEST_WF[Script Filter] Script with argv 'r' finished
[18:37:21.651] TEST_WF[Script Filter] {
	"items": [
		{
			"title": "HELLO\n",
			"subtitle": "Press ⌘L to see the full error and ⌘C to copy it.",
			"valid": false,
			"text": {
				"copy": "```\nHELLO\n```\n\n-\nTEST_WF undefined\nAlfred 5.0\ndarwin 21.6.0",
				"largetype": "HELLO"
			},
			"icon": {
				"path": "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertStopIcon.icns"
			}
		}
	]
}
{
	"items": [
		{
			"title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
			"arg": 1
		},
		{
			"title": "ea molestias quasi exercitationem repellat qui ipsa sit aut",
			"arg": 3
		},
...shortened 
   ]
}
[18:37:21.659] ERROR: TEST_WF[Script Filter] JSON error: Garbage at end around line 17, column 0. in JSON:
{
	"items": [
		{
			"title": "HELLO\n",
			"subtitle": "Press ⌘L to see the full error and ⌘C to copy it.",
			"valid": false,
			"text": {
				"copy": "```\nHELLO\n```\n\n-\nTEST_WF undefined\nAlfred 5.0\ndarwin 21.6.0",
				"largetype": "HELLO"
			},
			"icon": {
				"path": "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertStopIcon.icns"
			}
		}
	]
}
{
	"items": [
		{
			"title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
			"arg": 1
		},
...shortened
	]
}
@sindresorhus
Copy link
Owner

alfy.log simply passes it to console.error. Alfred documents that you can output to stderr for debugging.

https://www.alfredforum.com/topic/9170-alfred-3-tip-use-stderr-to-output-to-the-debug-console/

@hoto
Copy link

hoto commented Aug 14, 2022

I also don't understand how do you "console debug" anything using alfy without effectively breaking the workflow execution.
ATM it's either you get the debug logs or you get proper workflow execution, never both.

Any of the alfy/console logs will break the execution of the workflow:

import alfy from 'alfy'

alfy.log("my alfy.log()")
alfy.error("my alfy.error()")
console.info("my console.info()")
console.debug("my console.debug()")
console.error("my console.error()")

alfy.output(
    [
        {
            title: "My title"
        }
    ]
)

You will see the various log messages and My title being displayed in debug console, but the workflow execution will be broken, it crashes as alfred cannot parse the output.
Using any of the above logs crashes the exectuion of the workflow.

The big question here is how do you add debug log but at the same time don't crash the workflow execution?

@tkambler
Copy link

tkambler commented Aug 17, 2022

I'm also confused as to how this is supposed to work. I understand that alfy.log() is simply a wrapper around console.error(); however, when I try to use it, I end up seeing two items arrays getting printed to the console, which doesn't seem right.

FYI... If I comment out the following line in Alfy, everything works as expected:

// hookStderr(alfy.error);

Alfy seems to be trying to do two conflicting things with regards to stderr:

#86 (comment)

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

4 participants