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

Failing context operations like add, use, list, etc. #751

Closed
AnishKacham opened this issue Aug 9, 2023 · 19 comments · Fixed by #778
Closed

Failing context operations like add, use, list, etc. #751

AnishKacham opened this issue Aug 9, 2023 · 19 comments · Fixed by #778
Labels
bug Something isn't working

Comments

@AnishKacham
Copy link
Contributor

AnishKacham commented Aug 9, 2023

Context operations do not work even after initializing context

How to Reproduce

Create an empty directory, and spin up a sample asyncapi spec document.
for this I used the sample mentioned in the docs :

asyncapi config context init
you should see a .asyncapi-cli file get created with the following content:

{"store":{}}

now running asyncapi config context add foo ./asyncapi.yaml gives the following message even if context is initialized already

You have no context file configured. Run "asyncapi config context init" to initialize it.

Expected behavior

  • Context should be added to the .asyncapi-cli file
@AnishKacham AnishKacham added the bug Something isn't working label Aug 9, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Aug 9, 2023

Welcome to AsyncAPI. Thanks a lot for reporting your first issue. Please check out our contributors guide and the instructions about a basic recommended setup useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

@AnishKacham AnishKacham changed the title Failing context operations like add, use, etc. Failing context operations like add, use, list, etc. Aug 9, 2023
@derberg
Copy link
Member

derberg commented Aug 9, 2023

asyncapi config context add foo ./src -> can you please try adding a correct context? ./src is not a link to asyncapi file.

we need to make sure, maybe nothing is added to context, as the add fails (still something to fix, but we need to clarify)

@AnishKacham
Copy link
Contributor Author

AnishKacham commented Aug 9, 2023

oh alright.
You're right it isn't an asyncapi file. What could a correct context exactly be?
I haven't seen enough examples where context was used 😓. If you could point to some it'd be of great help

updated the issue a little bit to include a correct spec file as the argument to the command

@derberg
Copy link
Member

derberg commented Aug 10, 2023

@aeworxet hey any ideas?

@AnishKacham
Copy link
Contributor Author

update on this issue. The command works perfectly fine if I'm building cli locally and then using it as:

./bin/run config context add foo .\asyncapi.yaml

@derberg
Copy link
Member

derberg commented Aug 10, 2023

@AnishKacham when you tested a binary, how did you install it? npm install @asyncapi/cli -g or?

@AnishKacham
Copy link
Contributor Author

@AnishKacham when you tested a binary, how did you install it? npm install @asyncapi/cli -g or?

Yes. That is indeed how I installed asyncapi cli. the ./bin/run was from cloning the repository and running npm run build

@derberg
Copy link
Member

derberg commented Aug 10, 2023

getting the same with binary installed over npm:

$ asyncapi --version
@asyncapi/cli/0.52.3 darwin-x64 node-v16.13.0

$ asyncapi config context init
Initialized context /{...}/template-for-generator-templates-asyncapi-fork/.asyncapi-cli

$ cat .asyncapi-cli
{"store":{}}

$ asyncapi config context add dummy test/fixtures/dummy.yml
You have no context file configured. Run "asyncapi config context init" to initialize it.

@Souvikns
Copy link
Member

Souvikns commented Aug 10, 2023

I think it is working for me
Screenshot 2023-08-10 at 4 29 10 PM


Screenshot 2023-08-10 at 4 30 20 PM

@aeworxet
Copy link
Contributor

$ npm install @asyncapi/cli -g
[installed]

$ asyncapi --version
@asyncapi/cli/0.52.3 linux-x64 node-v18.9.0

$ asyncapi config context init
Initialized context /home/aeworxet/tmp_test/.asyncapi-cli

$ cat .asyncapi-cli
{"store":{}}

$ asyncapi config context add dummy test/fixtures/dummy.yml
Added context "dummy".

You can set it as your current context: asyncapi config context use dummy
You can use this context when needed by passing dummy as a parameter: asyncapi validate dummy

$ asyncapi config context list
dummy: test/fixtures/dummy.yml
$ node -v
v18.9.0

$ npm -v
8.19.2

host Linux
Ubuntu 20.04.6 LTS

@derberg @AnishKacham
Please share whether you use host Linux or some bash for Windows, like Git Bash/Cygwin.

@AnishKacham
Copy link
Contributor Author

AnishKacham commented Aug 10, 2023

$ node -v
v20.4.0

$ npm -v
9.7.2

$ asyncapi --version
@asyncapi/cli/0.52.3 win32-x64 node-v20.4.0

host Win11
via powershell
Not using Git Bash / Cygwin

" add works when you do it from location that is not git repo
so add fails only when you init for the repo. So probably loading context from repo root is problematic "

as discovered by @derberg
cc : @aeworxet @Souvikns

I've checked this and it seems like it is the issue.

@aeworxet
Copy link
Contributor

I was able to reproduce this issue only when I ran in Git Bash on Windows

$ npm install @asyncapi/cli -g
$ asyncapi config context init
$ asyncapi config context add dummy test/fixtures/dummy.yml

If I rebuild locally and run

$ npm run build
$ ./bin/run config context init
$ ./bin/run config context add dummy test/fixtures/dummy.yml

everything works.
So the issue is in combination of Windows and the prebuilt binary, and it doesn't depend on the version of Node.js.

$ node -v
v14.17.6

UPD.
Strange observation:
When I run in Git Bash on Windows

$ asyncapi config context init
$ asyncapi config context add dummy test/fixtures/dummy.yml

in the root of cloned cli repo I GET reproduction.
When I run same commands in another directory which also contains directory .git, I DO NOT get the reproduction.

@aeworxet
Copy link
Contributor

Diff shows no difference between prebuilt and locally built packages.

image

@aeworxet
Copy link
Contributor

I have narrowed the search for this bug.
The bug is not reproduced when file oclif.manifest.json is removed from prebuilt @asyncapi/cli package.
When cli package is built locally it does not include oclif.manifest.json file, that is why the bug is not reproduced when using the locally built package.

@derberg
Copy link
Member

derberg commented Aug 31, 2023

oh lovely, we at least can reproduce now on local. The oclif.manifest.json must stay. Maybe we should consider to generate it on local too, and just add to .gitignore

@derberg
Copy link
Member

derberg commented Aug 31, 2023

just opened a PR with fix that should solve the problem, at least works on my machine 😄

@aeworxet
Copy link
Contributor

Works on my machine too.
@AnishKacham does change from PR #778 work on your machine?

@AnishKacham
Copy link
Contributor Author

Works on my machine too. @AnishKacham does change from PR #778 work on your machine?

Yess. That works as expected on my machine. 🎉

@aeworxet
Copy link
Contributor

aeworxet commented Sep 4, 2023

The code works on three machines in different tech environments, in three different states. Should be good to merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants