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

[6.2] Cannot read properties of undefined (reading 'logOutput') #424

Closed
trin4ik opened this issue Jun 3, 2022 · 3 comments
Closed

[6.2] Cannot read properties of undefined (reading 'logOutput') #424

trin4ik opened this issue Jun 3, 2022 · 3 comments

Comments

@trin4ik
Copy link

trin4ik commented Jun 3, 2022

Expected Behavior

working

Actual Behavior

not workink )

Steps to Reproduce the Problem

on 6.2.+ get error

trin@StayHome:~/develop/cargo/deploy$ npm i -g zx@6.2.0
trin@StayHome:~/develop/cargo/deploy$ ./test.mjs
$ pwd
file:///home/trin/.local/lib/node_modules/zx/build/print.js:32
    let { logOutput = output, logFormat = () => msg, logPrint = printStd, logIgnore = [], } = ctx;
          ^

TypeError: Cannot read properties of undefined (reading 'logOutput')
    at log (file:///home/trin/.local/lib/node_modules/zx/build/print.js:32:11)
    at Socket.onStdout (file:///home/trin/.local/lib/node_modules/zx/build/core.js:186:17)

on 6.1.- all ok

trin@StayHome:~/develop/cargo/deploy$ npm i -g zx@6.1.0
trin@StayHome:~/develop/cargo/deploy$ ./test.mjs 
$ pwd
/home/trin/develop/cargo/deploy

Specifications

  • Version: 6.2.*
  • Platform: ubuntu 21.10
@antonmedv
Copy link
Collaborator

@antongolub please take a look.

@antongolub
Copy link
Contributor

antongolub commented Jun 3, 2022

@trin4ik, can you show how $ is loaded? It seems that rootCtx is empty, but we need to know why this happens.
We'd like to add a test for this case.

@trin4ik
Copy link
Author

trin4ik commented Jun 3, 2022

@trin4ik, can you show how $ is loaded? It seems that rootCtx is empty, but we need to know why this happens. We'd like to add a test for this case.

i dont know, what u mean "can u show how $ is loaded", i installed it like i wrote: npm i -g zx. i have node 16.13.1.
error on console:

trin@StayHome:~/develop/cargo/deploy$ zx ./test.mjs 
$ pwd
file:///home/trin/.local/lib/node_modules/zx/build/print.js:35
        let { logOutput = output, logFormat = () => msg, logPrint = printStd, logIgnore = [] } = ctx
              ^

TypeError: Cannot read properties of null (reading 'logOutput')
    at log (file:///home/trin/.local/lib/node_modules/zx/build/print.js:35:8)
    at Socket.onStdout (file:///home/trin/.local/lib/node_modules/zx/build/core.js:186:17)
...

in print.js i see

...
export function log (opts, ...msg) {
	let { scope, verbose = 1, output, raw } = opts
	let ctx = getCtx()
>	let { logOutput = output, logFormat = () => msg, logPrint = printStd, logIgnore = [] } = ctx
	let level = Math.min(+getRootCtx().verbose, +ctx.verbose)
...

in context.js:

import { AsyncLocalStorage } from 'node:async_hooks';
let root;
const storage = new AsyncLocalStorage();
export function getCtx() {
    return storage.getStore();
}
export function setRootCtx(ctx) {
    storage.enterWith(ctx);
    root = ctx;
}
export function getRootCtx() {
    return root;
}
export const runInCtx = storage.run.bind(storage);

if i change let ctx = getCtx() on let ctx = getCtx() ?? getRootCtx(), all works fine

P.s. Собрались как-то трое русских на гитхабе и кааааак давай практиковать английский...

antongolub added a commit to antongolub/zx that referenced this issue Jun 3, 2022
@antongolub antongolub mentioned this issue Jun 3, 2022
1 task
antongolub added a commit to antongolub/zx that referenced this issue Jun 3, 2022
antonmedv pushed a commit that referenced this issue Jun 4, 2022
* fix: bind fetch output to log()

* fix: use root ctx as getCtx fallback

closes #424

* refactor: simplify

* refactor: rm deep-proxy

* chore: revert shell tweak

* chore: protect promise.ctx from accidental removal

* test: test promise.ctx guard

* fix: use root as fallback for `runInCtx`
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

3 participants